我正在尝试执行以下简单操作:
<?php
header("Content-Type: text/html;charset=UTF-8");
$con=mysqli_connect("localhost","dsdsds","test1234","dsdsds");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM discounts");
while($row = mysqli_fetch_array($result))
{
echo $row['name'] . " " . $row['rate'];
echo "<br>";
}
?>
当我这样做时,我的输出显示为??????。在数据库表中,它正确显示为阿拉伯语。我究竟做错了什么?我也知道我应该添加代码以将 mysqli 设置为 utf8,当我这样做时,它会破坏脚本。
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
期待您的支持