utf 8 - PHP and MySQLi UTF8(utf 8 - PHP 和 MySQLi UTF8)
本文介绍了utf 8 - PHP 和 MySQLi UTF8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表字符集是 utf8,它的排序规则是 utf8.现在我有这个代码:
my table char set is utf8 and it's collation is utf8.now i have this code:
$mysqli = new mysqli("localhost", "root", "", "Amoozeshgah");
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
}
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s
", $mysqli->error);
} else {
printf("Current character set: %s
", $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
", $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
", $mysqli->error);
} else {
printf("Current character set: %s
", $mysqli->character_set_name());
}
mysql_set_charset('utf8');
与
$mysqli->set_charset("utf8")
但没有区别.
推荐答案
请将 mysql_set_charset('utf8'); 替换为 $mysqli->set_charset("utf8")代码> :-)
Please replace mysql_set_charset('utf8'); to $mysqli->set_charset("utf8") :-)
这篇关于utf 8 - PHP 和 MySQLi UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:utf 8 - PHP 和 MySQLi UTF8
基础教程推荐
猜你喜欢
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
