Home > Article > Backend Development > PHP solves the problem of Incorrect string value: 'xF0x9Fx92x8BTi...'Error when inserting data into MySQL_PHP Tutorial
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));
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);
If you want a perfect solution, it is best to upgrade MySql and directly change the data type to utf8mb4