如何将Emoji (UTF8 4字节字符)插入到MySQL

时间:2023-01-06 14:46:50

I have a website that connects with iPhone and Android users. They sometimes use UTF8MB4 characters (Emoji). When inserting those characters in strings in my MySQL database (formatted UTF8) the data was cropped at the first emoji.

我有一个连接iPhone和Android用户的网站。他们有时使用UTF8MB4字符(Emoji)。在我的MySQL数据库(格式化后的UTF8)中,当将这些字符插入字符串时,数据在第一个表情符处被裁剪。

Unfortunately, my hoster is running MySQL 5.1.66 and is not planning to update to a newer version yet. So what is the best solution for temporary use without switching the encoding?

不幸的是,我的hoster正在运行MySQL 5.1.66,并且还没有计划更新到更新的版本。那么,在不切换编码的情况下,临时使用的最佳解决方案是什么?

1 个解决方案

#1


15  

I have searched the web for many hours and I came to this solution which I want to share for other people:

我在网上搜索了好几个小时,终于找到了我想和大家分享的解决方案:

Use BLOB instead of text/varchar in the database fields. Like this, you can continue to use the database tables as you did before and the Emojis are shown properly. As soon as the hoster updates the MySQL version, I will continue with using UTF8MB4 as encoding.

在数据库字段中使用BLOB代替文本/varchar。像这样,您可以像以前那样继续使用数据库表,并正确地显示表情符号。一旦hoster更新了MySQL版本,我将继续使用UTF8MB4作为编码。

#1


15  

I have searched the web for many hours and I came to this solution which I want to share for other people:

我在网上搜索了好几个小时,终于找到了我想和大家分享的解决方案:

Use BLOB instead of text/varchar in the database fields. Like this, you can continue to use the database tables as you did before and the Emojis are shown properly. As soon as the hoster updates the MySQL version, I will continue with using UTF8MB4 as encoding.

在数据库字段中使用BLOB代替文本/varchar。像这样,您可以像以前那样继续使用数据库表,并正确地显示表情符号。一旦hoster更新了MySQL版本,我将继续使用UTF8MB4作为编码。