This article introduces the functions commonly used in php mysql programming to escape special characters, including the usage of the mysql_escape_string and addslashes functions. Friends in need can refer to it.
php mysql function to escape special characters Function one is mysql_escape_string, function two is addslashes. The difference between mysql_escape_string and addslashes is that mysql_escape_string always converts "'" to "'"And addslashes Convert "'" to """ when magic_quotes_sybase=on Convert "'" to "'" when magic_quotes_sybase=off PHP provides some functions to make the query statement meet the requirements. For example, mysql_escape_string references a string and returns a result, which can be used as an appropriately escaped data value in an SQL statement. The string is returned surrounded by single quotes, and every occurrence of a single quote ("'"), backslash (""), ASCII NUL, and Control-Z in the string is preceded by that character. Add a backslash. If the argument is NULL, the result value is the word "NULL" without single quotes. The QUOTE function was added in MySQL 4.0.3. Recommended reading: php character escape function reference, php regular expression escape character examples, I hope it can help everyone understand how to handle escape characters and special characters in PHP programming. When writing data to the database, sometimes the string to be written contains some special characters, such as ',",/,%, etc. I don't know if MySQL itself has such an escaping function, not those APIs . |