我有一个wordpress网站,由于某种原因,所有使用阿拉伯语的记录值都更改为موقع الطب النÙسي
,尽管数据库及其表格排序utf8mb4_unicode_ci
。为了解决这个问题,我决定使脚本从每个表中选择所有记录,然后iconv
每个值都是这样的عنوان باللغة العربية
。
现在问题我已经尝试了一切,但这对我不起作用
header('Content-Type: text/html; charset=utf-8');
$sql['host'] = "localhost";
$sql['username'] = "root";
$sql['password'] = "";
$sql['database'] = "nafsynet_database";
$connection = mysqli_connect($sql['host'], $sql['username'], $sql['password'], $sql['database']);
if (!$connection) {
$out .= "Error: Unable to connect to MySQL." . PHP_EOL;
$out .= "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
$out .= "Debugging error: " . mysqli_connect_error() . PHP_EOL;
echo $out;
die();
}
$sql = "SELECT * FROM `nfsy_options` WHERE 1 LIMIT 10";
$result = mysqli_query($connection, $sql);
$rows = mysqli_fetch_all($result,MYSQLI_ASSOC);
foreach($rows as $row) {
$text = $row['option_value'];
echo iconv('windows-1256', 'utf-8',$text);echo'<br>';
}
mysqli_close($connection);
答案 0 :(得分:2)
您还需要通过调用mysqli_set_charset
为数据库连接指定utf8字符集$connection = mysqli_connect($sql['host'], $sql['username'], $sql['password'], $sql['database']);
if (!$connection) {
// ..
}
mysqli_set_charset($connection, 'utf8');
$sql = "SELECT * FROM `nfsy_options` WHERE 1 LIMIT 10";