Just for clarity, can anyone explain why mysqli_real_escape_string
has to read:
$query = mysqli_real_escape_string($conn,"SELECT * FROM tbl");
And not just:
$query = mysqli_real_escape_string("SELECT * FROM tbl");
Thanks for any help!
Just for clarity, can anyone explain why mysqli_real_escape_string
has to read:
$query = mysqli_real_escape_string($conn,"SELECT * FROM tbl");
And not just:
$query = mysqli_real_escape_string("SELECT * FROM tbl");
Thanks for any help!
Because of charset encoding.
Without the $conn
, mysqli_real_escape_string()
won't be able to detect which character encoding the connection is using, and will blindly try to escape common dangerous characters - leaving some potentially dangerous charset hacks to go through.
True (not emulated) prepared statements are even better (or more secure, as you prefer), as they take the character encoding of the column instead of the connection into account.