当前位置:网站首页>How to handle the database query error with Emoji expression in Typecho- Xingze V Club

How to handle the database query error with Emoji expression in Typecho- Xingze V Club

2022-06-10 23:46:00 Xingze V Club

When writing today, insert emoji Look unexpectedly 「Database Query Error」 Report errors ,Typecho Not supported by default Emoji expression , This is not a procedural pot , But because of the coding problem . Emoji It's a kind of Unicode be located u1F601-u1F64F The characters of the section . This obviously goes beyond the current common UTF-8 The encoding range of the character set u0000-uFFFF. stay MySQL in ,UTF-8 Only support the most 3 Bytes , and Emoji yes 4 Bytes . So the comments have Emoji The expression will report an error .

We only need two simple steps to make typecho Support emoji Expression comment , Just encode the default database utf8 It is amended as follows utf8mb4 that will do .

1. Modify the code of the comment content field Use database management tools , find typecho_contents Comment form text Field , Change the code of this field to utf8mb4_general_ci.

If it is a comment that cannot be used, find typecho_comments Comment form text Field , Change the code of this field to utf8mb4_general_ci.

All changed , I've changed everything , All have been changed and can be inserted globally emoji Expression, etc .

Run the following code :

alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_options convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_users convert to character set utf8mb4 collate utf8mb4_general_ci;

2. Modify the database configuration file Open the website root database configuration file config.inc.php take charset The value of is determined by utf8 Change it to utf8mb4 .

/**  Define database parameters  */
$db = new Typecho_Db('Pdo_Mysql', 'echo_');
$db->addServer(array (
  'host' => 'localhost',
  'user' => 'echo',
  'password' => 'password',
  'charset' => 'utf8mb4', // Modify this parameter 
  'port' => '3306',
  'database' => 'echo',
), Typecho_Db::READ | Typecho_Db::WRITE);
Typecho_Db::set($db);

Save after modification . nice~

原网站

版权声明
本文为[Xingze V Club]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020933399312.html

随机推荐