PHP MySQL Escape special character function

Source: Internet
Author: User
Tags php mysql php regular expression
This article introduces the PHP MySQL programming special characters of the common functions, learning the implementation of the PHP escape character, the need for a friend reference.

In PHP MySQL programming, escape special characters: one is: mysql_escape_string

One 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, it provides some functions to make your query statements conform to your requirements, such as mysql_escape_string

References a string and returns a result that can be used as an appropriately escaped data value in an SQL statement. The string is enclosed in quotation marks around the return, and in that string each single quotation mark ("'"), backslash ("\"), ASCII NUL, and Control-z appear where the character is preceded by a backslash. If the argument is null, then the result value is a word "NULL" that is not surrounded by single quotes. The QUOTE function was added in MySQL 4.0.3. When writing data to the database, sometimes the string to be written contains some special characters, such as ', ',/,%, etc., do not know that MySQL itself has no such escape function, not those APIs. Special character escaping method in URL link php special character escape details php regular expression escaped character example PHP common escape character function PHP escape regular expression character function PHP implementation anti-injection and form commit value escaped code the method of escaping the character in the MySQL statement example PHP character escapes considerations

  • 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.