MYSQL utf8mb4 inserts garbled emoji expressions

WBOY
Release: 2016-08-04 09:21:14
Original
1598 people have browsed it

Questions about MYSQL utf8mb4 string set.

The table structure is as follows:

MYSQL utf8mb4 inserts garbled emoji expressions

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>
Copy after login
Copy after login

But after storage, it is a ? as shown below:

MYSQL utf8mb4 inserts garbled emoji expressions

Looking for a solution.

Reply content:

Questions about MYSQL utf8mb4 string set.

The table structure is as follows:

MYSQL utf8mb4 inserts garbled emoji expressions

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>
Copy after login
Copy after login

But after storage, it is a ? as shown below:

MYSQL utf8mb4 inserts garbled emoji expressions

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template