Home  >  Article  >  Backend Development  >  PHP solves the problem of Incorrect string value: 'xF0x9Fx92x8BTi...'Error when inserting data into MySQL_PHP Tutorial

PHP solves the problem of Incorrect string value: 'xF0x9Fx92x8BTi...'Error when inserting data into MySQL_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:30926browse

php solves the problem of Incorrect string value: 'xF0x9Fx92x8BTi...'Error

When inserting data into MySQL in the project, I found that the data insertion was incomplete. Through debugging, I found that there were no special errors in the insertion statement. But I just couldn’t get in, so I turned on mysqli error debugging

$ret = mysqli_query($this->conn, $sql) or die(mysqli_error($this->conn));


The following error message pops up:

Incorrect string value: 'xF0x9Fx92x8BTi...'


If there is an error message, it will be easy to handle. After checking online, the result is: mysql encoding format is utf-8 format, which does not support the insertion of four-byte strings.


There are two methods available online:

1. Upgrade MySQL, and then change the corresponding data type to utf8mb4 type

2. Filter or convert the four-byte UTF-8 characters that appear into a custom type


Since the installed MySQL version is 5.1, method 1 is not suitable; I chose the second filter string and turned it into a suitable 3-byte utf-8

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

Although it is still not a perfect solution, it at least ensures that every piece of data can be inserted correctly!

If you want a perfect solution, it is best to upgrade MySql and directly change the data type to utf8mb4




www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847860.htmlTechArticlephp solves the problem of Incorrect string value when inserting data into MySQL: #39;xF0x9Fx92x8BTi...#39;The error is in the project When inserting data into MySQL, it was found that the data insertion was incomplete. Through debugging, I found...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn