php读取mysql中文乱码

连接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

保证了三者之间的统一,就不会有乱码了。

原文地址:https://www.cnblogs.com/nannanITeye/p/3431738.html