PHP函数更改MySQL数据库的排序规则

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP函数更改MySQL数据库的排序规则相关的知识,希望对你有一定的参考价值。

Function to fix char set and collation on mysql tables, see [this link](http://www.barattalo.it/2010/02/11/php-function-to-fix-collation-on-database-fields-of-mysql/ "Fix encoding on db")
for examples and more infos.
  1. function fix_encoding($reg='//',$set='utf8',$collation='utf8_general_ci') {
  2. $res = mysql_query("SHOW TABLES");
  3. while ($row = mysql_fetch_row($res)) {
  4. if (preg_match($reg,$row[0])) {
  5. mysql_query("ALTER TABLE " . $row[0] . " CONVERT TO CHARACTER SET $set COLLATE $collation");
  6. echo $row[0] . " converted<br />";
  7. }
  8.  
  9. }
  10. }

以上是关于PHP函数更改MySQL数据库的排序规则的主要内容,如果未能解决你的问题,请参考以下文章

更改SQL Server 2012 数据库排序规则

MySQL - 错误 1071 阻止更改字符集/排序规则,“指定的键太长......”

在 phpmyadmin 中更改默认排序规则

哪个 MySQL 排序规则与 PHP 的字符串比较完全匹配?

如何在不转换列的情况下更改 MySQL 中的表(默认)排序规则[重复]

mysql8加密规则更改