Php solves the problem of Incorrect string value: '\ xF0 \ x9F \ x92 \ x8BTi...' when inserting MySQL Data. xf0x9f
When inserting data into MySQL in the project, it is found that the data insertion is incomplete. Through debugging, it is found that the insert statement has no special errors. 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{10FFFF}]/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.
The incorrect string value problem occurs when importing data in mysql.
Use show variables like 'character % 'to view the database encoding;
View the encoding of file C:/data/201109/all.txt,
The two are the same.
You can use the alter table name convert to character set encoding format. It is best to back up data in advance to avoid exceptions.
Save the file directly and select encoding. UTF-8 whenever possible
Php Database Error insert: Incorrect string value
The following content is to be inserted: Yingde is the hometown of sugar oranges in China ". Change $ contentsql: 1. $ contentsql = "insert into '$ contenttable' ('nid ',