Examples of methods for escaping characters in MySQL statements

Source: Internet
Author: User
When inserting a string with single or double quotation marks in a MySQL database, consider escaping with a backslash if it is a single string, what if a large amount of data needs to be converted? Refer to the introduction in this article.

If you have a large amount of content that needs to be escaped, consider the mysql_real_escape_string function: mysql_real_escape_string-escapes the special characters in the string used in the SQL statement and takes into account the current character set of the connection.

Note: This function does not escape% and _. In addition, it is best not to use the function for the entire SQL statement, but only to escape the string parameters of the incoming SQL statement, otherwise it will silently appear.

Example:

     
     

Test it in your own program to see how the escaped result is.

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