Which of the following functions escape special characters in phpmysql?

Source: Internet
Author: User
Which of the following functions escape special characters in phpmysql?
This article describes the functions commonly used to escape special characters in php mysql programming, including the usage of mysql_escape_string and addslashes functions. For more information, see.

Functions for escaping special characters in php mysql

Function 1 is mysql_escape_string, and function 2 is addslashes.

The difference between mysql_escape_string and addslashes is that mysql_escape_string always converts "'" to "\".

Addslashes converts "'" to "when magic_quotes_sybase = on.

When magic_quotes_sybase = off, convert "'" to "\'" php. some functions are provided to make the query statement meet the requirements. for example, mysql_escape_string references a string and returns a result, this result can be used as a properly escaped data value in an SQL statement. A string is enclosed by single quotes and returned, where each single quotation mark ("'"), backslash ("\"), ascii nul, and Control-Z appear in the string, A backslash is added before the character. If the parameter is NULL, the result value is the word "NULL" without single quotes ". QUOTE function is added in MySQL 4.0.3. We recommend that you read: php character escape function reference, php regular expression escape character example, hope to help you understand the handling methods of intermediate and special characters in php programming.

When writing data to a database, sometimes the string to be written contains some special characters, such as ',', //, %, etc, I don't know if mysql has such escape functions, not those APIs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.