如何将表情符号(UTF8 4字节字符)插入MySQL< 5.5 [英] How to insert Emoji (UTF8 4 Byte characters) into MySQL < 5.5

查看:102
本文介绍了如何将表情符号(UTF8 4字节字符)插入MySQL< 5.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以与iPhone和Android用户联系的网站.他们有时使用UTF8MB4字符(表情符号).当在我的MySQL数据库(格式为UTF8)中的字符串中插入这些字符时,数据将在第一个表情符号处裁剪.

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.

不幸的是,我的托管服务商正在运行MySQL 5.1.66,并且尚未计划更新到较新版本.那么在不切换编码的情况下临时使用的最佳解决方案是什么?

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?

推荐答案

我已经在网上搜索了多个小时,并且想到了要与其他人分享的解决方案:

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

在数据库字段中使用BLOB代替text/varchar.这样,您可以像以前一样继续使用数据库表,并且表情符号可以正确显示.托管人更新MySQL版本后,我将继续使用UTF8MB4作为编码.

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.

这篇关于如何将表情符号(UTF8 4字节字符)插入MySQL< 5.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆