MYSQL utf8mb4 insertion Emoji emoticons garbled

Source: Internet
Author: User

Questions about the MySQL utf8mb4 string set.

The table structure is as follows:

The following code:

$db     = new mysqli('x', 'xxx', 'xxxxx');$db->select_db('xxx');$db->set_charset('utf8mb4');//这里是一个emoji表情$contents = <<
  
   
    
   query($sql);print_r($db->error_list);echo "\t\n";exit();
  
   

But after warehousing, is a ? such as:

Solution.

Reply content:

Questions about the MySQL utf8mb4 string set.

The table structure is as follows:

The following code:

$db     = new mysqli('x', 'xxx', 'xxxxx');$db->select_db('xxx');$db->set_charset('utf8mb4');//这里是一个emoji表情$contents = <<
  
   
    
   query($sql);print_r($db->error_list);echo "\t\n";exit();
  
   

But after warehousing, is a ? such as:

Solution.

That's right.
Under the premise, the difference between utf8mb4 and UTF8 is that UTF8 uses 3-bit bytecode to store data, while UTF8MB4 stores data with 4-bit byte codes.
Emoji expression is a 4-bit bytecode escaped through the previous paragraph, which itself is unreadable characters, so in the database client will display "? ”。
The emoji expression is displayed where the front-end support is emoji.

Determine if the client supports UTF8MB4, preferably when set names is used.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.