Questions about MYSQL utf8mb4 string set.
The table structure is as follows:
The following code:
<code class="php">$db = new mysqli('x', 'xxx', 'xxxxx'); $db->select_db('xxx'); $db->set_charset('utf8mb4'); //这里是一个emoji表情 $contents = <<<EOT "\ud83d\udca5" EOT; $contents = json_decode($contents). "hello"; echo $contents, "\t\n"; $sql = "INSERT INTO `utf8mb4`(`contents`) VALUES('$contents')"; echo $sql, "\t","\n"; $db->query($sql); print_r($db->error_list); echo "\t\n"; exit();</code>
But after storage, it is a ?
as shown below:
Looking for a solution.
Questions about MYSQL utf8mb4 string set.
The table structure is as follows:
The following code:
<code class="php">$db = new mysqli('x', 'xxx', 'xxxxx'); $db->select_db('xxx'); $db->set_charset('utf8mb4'); //这里是一个emoji表情 $contents = <<<EOT "\ud83d\udca5" EOT; $contents = json_decode($contents). "hello"; echo $contents, "\t\n"; $sql = "INSERT INTO `utf8mb4`(`contents`) VALUES('$contents')"; echo $sql, "\t","\n"; $db->query($sql); print_r($db->error_list); echo "\t\n"; exit();</code>
But after storage, it is a ?
as shown below:
Looking for a solution.
This is right.
Let’s talk about the premise. The difference between utf8mb4 and utf8 is that utf8 only uses 3-bit bytecode to store data, while utf8mb4 uses 4-bit bytecode to store data.
The emoji expression is a 4-bit bytecode escaped through the previous paragraph. It is an unreadable character itself, so "?" will be displayed in the database client.
Emoji expressions will be displayed where the front end supports emoji.
Determine whether the client supports utf8mb4. It is best to use set names.