Typecho使用emoji表情包时,插入数据库失败 2021-11-25 22:45:00 编程 Typecho 暂无评论 740 次阅读 1221字 修改时间:2021-11-26 13:26:44 Typecho 默认的数据库编码格式是utf-8,这导致使用emoji表情包时,插入数据库失败 这是因为emoji在Unicode位于`\u1F601-\u1F64F`区段的字符。这个显然超过了目前常用的UTF-8字符集的编码范围`\u0000-\uFFFF` 1.修改Typecho数据编码格式为utf8mb4 ```sql alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_options convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_users convert to character set utf8mb4 collate utf8mb4_unicode_ci; ``` 2.修改Typecho的**config.inc.php** 配置文件,将**'charset'**更改为**utf8mb4** /** 定义数据库参数 */ ```php $db = new Typecho_Db('Pdo_Mysql', 'typecho_'); $db->addServer(array ( 'host' => '127.0.0.1', 'user' => 'root', 'password' => 'root123', 'charset' => 'utf8mb4', 'port' => '3306', 'database' => 'typecho', ), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db); ``` 标签: Typecho
评论已关闭