Functions for escaping special characters in PHP MySQL

Source: Internet
Author: User
Tags php mysql

Functions for escaping special characters in PHP MySQL

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 provides some functions to make your query statement meet your requirements, such as mysql_escape_string.

Reference a string and return a result. The 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.

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.