php中文字符乱码,中文字符入库乱码的问题
在将中文字符数据写入数据库时,会有乱码,即你用mysql查询时,全是一些???这样的字符。
出现这种情况的根源在于:未明确告诉mysql数据库将要插入的数据是gbk类型的。
解决方法:
在查询时定义字符类型:
mysql_query("set names 'gbk'")
下面是一个完整的示例,供大家参考。
<?php
/*
@中文字符入库乱码的解决方法
@www.php.cn
*/
include_once("conn.php");
include_once("include.php");
mysql_query("set names 'gbk'")or die("设置字符库失败\n");
mysql_select_db($db)or die("连接数据库失败!\n");
$exec = "select * from $table";
//echo $exec;
$result = mysql_query($exec,$conn)or die("查询数据库失败\n");
echo "<table border=2>";
for($cout=0;$cout<mysql_numrows($result);$cout++)
{
$city = mysql_result($result,$cout,city);
$name = mysql_result($result,$cout,name);
$phone = mysql_result($result,$cout,phone);
echo "<tr>";
echo "city: $city";
echo "name: $name";
echo "phone: $phone";
echo "</tr>";
}
echo "</table>";
?>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号