How to insert a backslash in MySQL, a backslash is eaten, and a backslash is escaped

Source: Internet
Author: User

How to insert a backslash in MySQL, a backslash is eaten, and a backslash is escaped

Problem Description:
After the contents of the backslash in MySQL are put into storage, the backslash is found to be missing for no reason (as the old saying is eaten)
Example: inserting INSERT into TB (' URL ') VALUES (' absc\eeee '); The results in the database are: absceeee (the backslash is gone)

In this detail, I believe we all know the problem, see the solution below.

Solution:
Use Addslashes (), mysql_escape_string () and other functions for processing, that is, before inserting the database, the content is processed
such as: $CC = addslashes (' absc\eeee '); INSERT into TB (' URL ') values ($CC);

Suddenly found good also, there is no. But what happened in the middle, do you know, and then look down-""

What happened:
When MySQL inserts the database, it automatically removes the escape character, the backslash "\", Addslashes (), and mysql_escape_string () uses these functions to add a backslash before the backslash, which is the absc\\eeee. In the storage when the first backslash is considered to be an escape character, the second backslash is considered to be normal content, so remove the first backslash, keep the second one, see the result is the backslash inserted.

Go

How to insert a backslash in MySQL, a backslash is eaten, and a backslash is escaped (go)

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.