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

查看:96
本文介绍了如何将表情符号(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天全站免登陆