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?

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

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题