When inserting data into MySQL in a project, it is found that data insertions are incomplete and there is no special error in inserting statements through debugging. But just don't go in, and then open mysqli error debugging
$ret = Mysqli_query ($this->conn, $sql) or Die (Mysqli_error ($this->conn));
The result pops up the following error message:
Incorrect string value: ' \xf0\x9f\x92\x8bti ... '
The error message is good to do, the results of the Internet search results are: MySQL encoded format utf-8 format, with four bytes of string insertion is not supported.
Online offers two ways:
1. Upgrade MySQL, and then change the corresponding data type to UTF8MB4 type
2. The four-byte UTF-8 character that appears filtered or converted to a custom type
Since the version of MySQL installed is 5.1, so Method 1 is not suitable; I chose the second filter string to fit into the 3-byte utf-8
$str = preg_replace ('/[\x{10000}-\x{10ffff}]/u ', ', ', $str);
Although it is still not a perfect solution, but at least ensure that each piece of data can be inserted correctly!
If you want to perfect solution, it is best to upgrade MySQL, directly change the data type for UTF8MB4 type