您的位置:首页 > 编程语言 > PHP开发

php读取mysql中文乱码

2013-11-19 16:35 232 查看
连接mysql的文件:

<?php
/*****************************
*数据库连接
*****************************/
$conn = @mysql_connect("localhost","root","123abcd");
if (!$conn){
exit("连接数据库失败:" . mysql_error());
}
mysql_select_db("location", $conn);
//字符转换,读库
mysql_query("set character set 'utf8'");
//写库
mysql_query("set names 'utf8'");
?>


网站页面的编码:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

mysql用utf8_unicode_ci。

保证了三者之间的统一,就不会有乱码了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: