- ·上一篇文章:phpMyAdmin Access denied for user
- ·下一篇文章:微软亚洲技术中心面试题曝光
从MySQL中获取中文数据
今天测试了一下从MySQL中获得中文数据,发现需要进行一些处理才能在网页中完美显示中文
首先,当然是你的MySQL数据库是基于UTF-8建立的。
然后是在PHP中的常规连接:
$hostname_test = “localhost”;
$database_test = “test”;
$username_test = “root”;
$password_test = “xxxxxx”;
$test = mysql_pconnect($hostname_test, $username_test, $password_test) or trigger_error(mysql_error(),E
$query=”select * from chinese”;
mysql_select_db($database_test, $test);
$xx=”set names utf8″;
mysql_query($xx);
$rs=mysql_query($query, $test);
while($row=mysql_fetch_object(
{
echo $row->id.”<br/>”;
echo $row->desc.”<br/>”;
echo “=====================<br/>”;
}
注意上面的黑体部分,这两行很关键。
再然后是在PHP文件中要指定字符集:
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
</head>
注意,这里要写utf-8,而set names时要写utf8。

