我的表字符集是utf8,它的排序规则是utf8。现在我有了以下代码:
$mysqli = new mysqli("localhost", "root", "", "Amoozeshgah");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
}
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());
}
mysql_set_charset('utf8');
if ($stmt = $mysqli->prepare("SELECT About_Title FROM Tbl_About WHERE About_Id=?")) {
$city = 8;
/* bind parameters for markers */
$stmt->bind_param("s", $city);
/* execute query */
$stmt->execute();
/* bind result variables */
$result = $stmt->get_result();
/* fetch value */
while ($myrow = $result->fetch_assoc()) {
// use your $myrow array as you would with any other fetch
printf("%s is in district %s\n", $city, $myrow['About_Title']);
print("shod");
}但输出结果是:
Current character set: utf8 8 is in district نتمنتشس shod我能做什么?编辑:我替换了:
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());
}
mysql_set_charset('utf8');使用
$mysqli->set_charset("utf8")但没什么不同。
发布于 2012-04-26 19:03:54
请将mysql_set_charset('utf8');替换为$mysqli->set_charset("utf8") :-)
发布于 2014-02-12 20:33:49
or mysqli_set_charset($this->mysqli,"utf8");
mysqli_set_charset($conn,"utf8");发布于 2020-07-08 16:42:39
以防您在代码中使用"json_encode“,例如:
json_encode($rows);只需将其更改为:
json_encode($rows,JSON_UNESCAPED_UNICODE);https://stackoverflow.com/questions/10331883
复制相似问题