I read lot of things about the common sql injection so got interested on how to fix them. Before I just used to use
addslashes()
thinking (badly) that it would fit. Then I discovered that mysql(i)_real_escape_string()
is way more useful and trustful than addslashes()
. Since then I use mysqli_real_escape_string()
but recently I got into something I haven't really understood.
I had some problem about sending datas to mysql and character set.
So, once again, I searched, and many users say that SET NAMES UTF8
is the way to make everything goes the correct way.
But then I read that using that query makes mysqli_real_escape_string()
not working.
So after all I got a little bit confused.
What's the correct way to escape a sql statement?
What are the possible exploits using SET NAMES UTF8
?
Is mysqli_set_charset()
the correct way to make the connection communicate in a specified charset?
Using mysqli_sey_charset()
are the mysql's internal variables cchanged in the process?
Thanks
Just to correct a lot of misinformation in both question and answers.
What's the correct way to escape a sql statement?
What are the possible exploits using SET NAMES UTF8?
None
Is mysqli_set_charset() the correct way to make the connection communicate in a specified charset?
Sure.
It have to be fed with the actual charset used on the HTML page.