Php solves the problem of Incorrectstringvalue: & amp; # _ MySQL when inserting data in MySQL.

Source: Internet
Author: User
Php solves the problem of Incorrectstringvalue: amp; # x27; xF0x9Fx92x8BTi when inserting MySQL data... amp; # x27; error when inserting data into MySQL in the project, it is found that the data insertion is incomplete. through debugging, it is found that there are no special errors in the insert statement. However, if the difference does not exist, debug the mysqli error.

$ Ret = mysqli_query ($ this-> conn, $ SQL) or die (mysqli_error ($ this-> conn ));

The following error message is displayed:

Incorrect string value: '/xF0/x9F/x92/x8BTi ...'

If there is an error message, you can check the result online. The result is that the mysql encoding format is UTF-8, and four-byte string insertion is not supported.

There are two methods available on the Internet:

1. upgrade MySQL and change the corresponding data type to utf8mb4.

2. the four-byte UTF-8 character appears to filter or convert to custom type

Because MySQL 5.1 is installed, Method 1 is not suitable. I chose the second filter string to convert it into a suitable 3-byte UTF-8

$ Str = preg_replace ('/[/x {10000}-/x {10 FFFF}]/U', '', $ str );

Although it still cannot be solved perfectly, at least ensure that each piece of data can be correctly inserted!

If you want to solve the problem perfectly, you 'd better upgrade MySql and change the data type to utf8mb4.

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.