北京SEO

mysql如何存储emoji表情

2019/10/10/17:32:40  阅读:1874  来源:谷歌SEO算法  标签: 云计算

在mysql中如何存储emoji表情,如果mysql是utf-8编码,存入表情符出错我们如何解决,下面我们来介绍一下.

utf8的数据库,存入表情符,会出错,代码如下:

Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F...' for column 'content'

错误的解决办法:

  1. 4byteUnicodecharactersaren'tyetwidelyused,sonoteveryapplicationouttherefullysupportsthem.MySQL5.5worksfinewith4bytecharacterswhenproperlyconfigured–checkifyourothercomponentscanworkwiththemaswell.
  2. Here'safewotherthingstocheckout:
  3. Makesureallyourtables'defaultcharactersetsandtextfieldsareconvertedtoutf8mb4,inadditiontosettingtheclient&servercharactersets,e.g.ALTERTABLEmytablecharset=utf8mb4,MODIFYCOLUMNtextfield1VARCHAR(255)CHARACTERSETutf8mb4,MODIFYCOLUMNtextfield2VARCHAR(255)CHARACTERSETutf8mb4;andsoon.
  4. Ifyourdataisalreadyintheutf8characterset,itshouldconverttoutf8mb4inplacewithoutanyproblems.Asalways,backupyourdatabeforetrying!
  5. Alsomakesureyourapplayersetsitsdatabaseconnections'charactersettoutf8mb4.Double-checkthisisactuallyhappening–ifyou'rerunninganolderversionofyourchosenframework'smysqlclientlibrary,itmaynothavebeencompiledwithutf8mb4supportanditwon'tsetthecharsetproperly.Ifnot,youmayhavetoupdateitorcompileityourself.//开源软件:phpfensi.com
  6. Whenviewingyourdatathroughthemysqlclient,makesureyou'reonamachinethatcandisplayemoji,andrunaSETNAMESutf8mb4beforerunninganyqueries.
  7. Onceeverylevelofyourapplicationcansupportthenewcharacters,youshouldbeabletousethemwithoutanycorruption.

总结就是:表结构改为支持4字节的unicode,数据库连接也用这个字符集哦,证明是可行的,如果别的地方不支持,可以考虑去掉这些字符:

  1. Since4-byteUTF-8sequencesalwaysstartwiththebytes0xF0-0xF7,thefollowingshouldwork:
  2. $str=preg_replace('/[\xF0-\xF7].../s','',$str);
  3. Alternatively,youcouldusepreg_replaceinUTF-8modebutthiswillprobablybeslower:
  4. $str=preg_replace('/[\x{10000}-\x{10FFFF}]/u','',$str);
  5. Thisworksbecause4-byteUTF-8sequencesareusedforcodepointsinthesupplementaryUnicodeplanesstartingfrom0x10000.

广告内容

mysql如何存储emoji表情 mysql如何存储emoji表情 mysql如何存储emoji表情

相关阅读

热门评论

木木老贼 木木老贼

互联网营销达人~

总篇数181

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法