Home > Backend Development > PHP Tutorial > mysql_set_charset("utf-8");乱码,但直接在数据库SQL输入通常

mysql_set_charset("utf-8");乱码,但直接在数据库SQL输入通常

WBOY
Release: 2016-06-13 12:43:05
Original
1375 people have browsed it

mysql_set_charset("utf-8");乱码,但直接在数据库SQL输入正常
$conn=mysql_connect("127.0.0.1","root","") or die("数据库服务器连接错误".mysql_error());
 $dbname="jiazheng";                            //选mysql数据库上的数据库名
 $aa=mysql_select_db($dbname,$conn) or die("数据库访问错误".mysql_errno());  

mysql_set_charset("utf-8");

 $sql="INSERT INTO `user`(`user`, `pwd`, `time`, `power`) VALUES ('BB我们的家乡','1111','2013-07-01','1')";
mysql_query($sql);
echo $sql;

mysql_close();
?>

在phpMyadmin中直接输入SQL语句,可以插入中文,不乱码。
但是,在PHP中就不行,为嘛呢?

乱码 数据库
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template