Home > Database > Mysql Tutorial > body text

PHP+MYSQL 出现乱码的解决方法_MySQL

WBOY
Release: 2016-06-01 13:51:51
Original
731 people have browsed it

使用PHP+MYSQL时遇到过字符乱问题,解决方法:

在mysql_connect后面加一句SET NAMES UTF8,即可使得UTF8的数据库消除乱码,对于GBK的数据库则使用SET NAMES GBK,代码如下:

1 $mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass); <br>2 mysql_query("SET NAMES 'GBK'"); 
Copy after login

数据库字符集为utf-8 

 连接语句用这个

1 mysql_query("SET NAMES 'UTF8'"); <br>2 mysql_query("SET CHARACTER SET UTF8"); <br>3 mysql_query("SET CHARACTER_SET_RESULTS=UTF8'"); 
Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!