Let your field support save the emoji expression in your phone

Source: Internet
Author: User

Yesterday in the mobile interface development, developer feedback, to the interface to include the value of the mobile phone input method in the emoji expression, the app is directly hung off. Find the reason, found that when inserting data into the database, error incorrect string value: ' \xf0\x9f\x92\xaa ',... ' for column ' content ' at row 1.
Now that you know the problem, go to the engine and search for the solution. Here are some things to know:
One.

The inserted field contains the emoji emoji. It is basically possible to determine the problem of character encoding. Our database is using UTF8 encoding, ordinary string or expression are occupied 3 bytes, so utf8 enough to use, but the mobile side of the emoji placeholder is 4 bytes, the ordinary utf8 is not enough, in order to deal with the wireless internet opportunities and challenges, to avoid emoji The problem with emoticons, the wireless-related MySQL database recommendations are in advance to adopt the UTF8MB4 character set, which must be the key to a technology selection in the mobile internet industry. UTF8 and utf8mb4 Description: Utf-8:unicode transformation Format-8bit, including BOM, but usually does not include BOM. is a multi-byte encoding used to solve the international character, which uses 8 bits (or one byte) in English, and Chinese uses 24 (three bytes) to encode. UTF-8 contains the characters that all countries in the world need to use, and is an international code with strong versatility. UTF-8 encoded text can be displayed on browsers that support the UTF8 character set in each country.  If it is UTF8 code, it can also display Chinese in the foreigner's English ie, they do not need to download IE's Chinese language support package. Utf8mb4:mysql added UTF8MB4 code after 5.5.3, Mb4 is the most bytes 4 meaning, specifically for compatibility with four-byte Unicode.


Two.ALTER table cnfol_dynamic MODIFY COLUMN content text CHARACTER set utf8mb4; (Modify the character set of the table field)

After you change the test, the insertion fails. ALTER TABLE cnfol_dynamic CONVERT to CHARACTER SET utf8mb4;(Modify the table's character set)[size=+0]
After you change the test, the insertion fails. ALTER DATABASE Caishi CHARACTER SET utf8mb4;  (Modify the library's character set) after the test is finished, the insertion fails. Finally try to modify the MySQL configuration file my.cnf
Vi/etc/my.cnf
Add under [client]
Default-character-set=utf8mb4
Add under [mysqld]
DEFAULT-CHARACTER-SET=UTF8MB4 modified the test, still error. Finally find the reason, when the PHP code to connect to the database, there is a set of options for setting character sets. This option should also be set to UTF8MB4. After all the above modifications are successful, the test is feasible. And does not affect the original data. UTF8MB4 is fully compatible with UTF8.

Let your field support save the emoji expression in your phone

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.