Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does mysql_real_escape_string() do that addslashes() doesn't?

Tags:

Why do we need a DB-specific functions like mysql_real_escape_string()? What can it do that addslashes() doesn't?

Ignoring for the moment the superior alternative of parameterized queries, is a webapp that uses addslashes() exclusively still vulnerable to SQL injection, and if yes, how?

like image 530
Michael Borgwardt Avatar asked Feb 10 '09 23:02

Michael Borgwardt


People also ask

What is the use of mysql_real_escape_string () function?

The real_escape_string() / mysqli_real_escape_string() function escapes special characters in a string for use in an SQL query, taking into account the current character set of the connection.

Does mysql_real_escape_string prevent SQL injection?

mysql_real_escape_string ALONE can prevent nothing. Moreover, this function has nothing to do with injections at all. Whenever you need escaping, you need it despite of "security", but just because it is required by SQL syntax.

Why does mysql_real_escape_string need a connection?

mysql_real_escape_string() and prepared statements need a connection to the database so that they can escape the string using the appropriate character set - otherwise SQL injection attacks are still possible using multi-byte characters.

Is mysql_real_escape_string deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.


1 Answers

Addslashes is generally not good enough when dealing with multibyte encoded strings.

like image 166
Chris KL Avatar answered Sep 21 '22 06:09

Chris KL