douzuo0711 2017-10-09 08:39
浏览 162
已采纳

表情符号(

I am trying to save emoji symbol to database record but each time it's not saving properly. I've referred this How to store Emoji Character in My SQL Database but still not working.
As per solution on above question, I tried to change the character set from utf8 to utf8mb4 and collation from utf8mb4_bin.

I tried everything like resetting to default and then changing it in the database table. I tried utf8mb4_unicode_ci, utf8_unicode_ci and utf8mb4_bin but it's not working.

I am using MySQL 5.6 version. And I am changing the collation with below query

alter table `users` convert to character set utf8mb4 collate utf8mb4_bin;

The above code is working fine, it's changing the UTF type in database. But emoji is not saving properly it's saving as question marks (????)

Below is my database table structure example:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'System generated id used for uniqueness',
  `introduction` longtext COLLATE utf8mb4_bin,
  `other_details` longtext COLLATE utf8mb4_bin,    
   PRIMARY KEY (`id`),
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=41213 ;


To save emoji using below PHP code:

$dom = new DOMDocument('1.0', 'UTF-8');
$strWithEmoji = "
  • 写回答

1条回答 默认 最新

  • dongzhenshen7435 2017-10-09 22:35
    关注

    The connection needs to specify utf8mb4 to MySQL. What is under the covers in DOMDocument?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条