gpt4 book ai didi

php - 导入 mySQL 数据 - 错误的字符集

转载 作者:行者123 更新时间:2023-11-29 12:44:26 25 4
gpt4 key购买 nike

我将网站迁移到另一个 ISP,但遇到了问题。我转储我的 mySQL 数据库,导入新的 ISP,当从网络连接时,我有不好的迹象,例如:“wy??�?czy?? si�? podczas u??ywania, nie uruchamia si�?,”

我来自波兰,所以我使用本地符号,如 ę、ą 等。我不知道字符集问题出在哪里,我不会在数据库中更改它。我如何转换此数据库或其他数据库来解决此问题?

function db_connect(){
$connect_support = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS)
or die('bd server');
mysql_select_db(SQL_DB)
or die('table');
//$charset = mysql_client_encoding($connect_support);
//echo "Charset is: $charset\n";
}

最佳答案

这就是我最终解决问题的方法:

首先mysqldump -用户名-密码--default-character-set=latin1数据库-r dump.sql

然后运行此脚本

$search = array('/latin1/');
$replace = array('utf8');
foreach (range(128, 255) as $dec) {
$search[] = "/\x".dechex($dec)."/";
$replace[] = "&#$dec;";
}

$input = fopen('dump.sql', 'r');
$output = fopen('result.sql', 'w');

while (!feof($input)) {
$line = fgets($input);
$line = preg_replace($search, $replace, $line);
fwrite($output, $line);
}

fclose($input);
fclose($output);

关于php - 导入 mySQL 数据 - 错误的字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25645796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com