Home >Backend Development >PHP Tutorial >Detailed explanation of the difference between php mysql_escape_string and addslashes_PHP tutorial
For a detailed explanation of the difference between php mysql_escape_string and addslashes, you can refer to this article.
The mysql_real_escape_string() function escapes special characters in strings used in SQL statements.
The following characters are affected:
•x00
•n
•r
•
•'
•"
•x1a
If successful, the function returns the escaped string. If failed, returns false.
The addslashes() function adds a backslash before the specified predefined characters.
These predefined characters are:
•Single quote (')
•Double quotes (")
•Backslash ()
•NULL
Summary of differences
The difference between mysql_escape_string and addslashes is
mysql_escape_string always converts "'" to "'"
And addslashes
Convert "'" to "''" when magic_quotes_sybase=on
Convert "'" to "'" when magic_quotes_sybase=off