PHP addslashes () function
$str addslashes (' Shanghai is the ' biggest ' ); Echo ($str);
The result is
Shanghai is the ' biggest\ City ' in China.
MySQL's mysql_real_escape_string () function definition and usage
The mysql_real_escape_string () function escapes special characters in strings used in SQL statements.
The following characters are affected:
If successful, the function returns the escaped string. If it fails, it returns false.
Grammar
Mysql_real_escape_string (string,connection)
| Parameters |
Description |
| String |
Necessary. Specifies the string to be escaped. |
| Connection |
Optional. Specify MySQL connection. If not specified, the previous connection is used. |
Description
This function escapes the special characters in the string and takes into account the current character set of the connection, so it can be used safely for mysql_query ().
Can be defined as a method
function escapestring ($data)
{
Return mysql_real_escape_string ($data, $this->RESOURC);
}
Call this function later to
PHP anti-injection escape function