Home > Backend Development > PHP Tutorial > What are the functions for php mysql to escape special characters?

What are the functions for php mysql to escape special characters?

WBOY
Release: 2016-07-25 08:53:01
Original
1001 people have browsed it
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 .



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template