Why is it recommended to use UTF8MB4 encoding in a database?

Source: Internet
Author: User
Database-level UTF-8

If you use PHP to operate to MySQL, sometimes even if you do all of the above, your string may still face the problem of storing it in a non-UTF-8 format in the database.
To ensure that your strings are used UTF-8 from PHP to MySQL, check that your database and data tables are set to UTF8MB4 character set and collation, and make sure that your PDO connection request also uses the UTF8MB4 character set. See the example code below, which is very important.
Please note that for full UTF-8 support, you must use UTF8MB4 instead of utf8! You'll find out why in the further reading.

    • The above is written in Php-the-right-way, not too clear, ask for answers.

Thank you for your reply, I found the detailed information on the Internet.

MYSQL:UTF8MB4 's Problem

MySQL utf8mb4 with emoji expression

Reply content:

Database-level UTF-8

If you use PHP to operate to MySQL, sometimes even if you do all of the above, your string may still face the problem of storing it in a non-UTF-8 format in the database.
To ensure that your strings are used UTF-8 from PHP to MySQL, check that your database and data tables are set to UTF8MB4 character set and collation, and make sure that your PDO connection request also uses the UTF8MB4 character set. See the example code below, which is very important.
Please note that for full UTF-8 support, you must use UTF8MB4 instead of utf8! You'll find out why in the further reading.

    • The above is written in Php-the-right-way, not too clear, ask for answers.

Thank you for your reply, I found the detailed information on the Internet.

MYSQL:UTF8MB4 's Problem

MySQL utf8mb4 with emoji expression

Emoji expression can only use UTF8MB4 storage, normal text only need 3byte storage, emoji need four

There are some Martian texts that can only be expressed in utf8mb4, and the UTF8 of MySQL implementation cannot

UTF8MB4 only supports emoji expression storage.

  • 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.