Home > Database > Mysql Tutorial > PHP+MYSQL中文乱码解决方案_MySQL

PHP+MYSQL中文乱码解决方案_MySQL

WBOY
Release: 2016-06-01 13:44:56
Original
908 people have browsed it

bitsCN.com

在mysql console中输入show variables like "character%";运行结果如下图所示:

PHP+MYSQL中文乱码解决方案_MySQL

把上图value的12356行统一设置成GBK或UTF-8就可以解决这个问题。
一、首先看1、2、5行。
在PHP所有用到MYSQL的地方,先执行"set names gbk"或者"set name utf8";
二、然后看第三行,也就是character_set_database。
可以在mysql console中输入alter database 'databasename' default character set gbk collate gbk_chinese_ci;或者alter database 'databasename' default character set utf8 collate utf8_general_ci;运行。
三、最后就是第六行。
打开my.ini,找到default-character-set,修改为default-character-set=gbk或者default-character-set=utf-8,共两处。找不到可自行在[mysql]、[mysqld]后分别加上。
做完以上操作,就OK了。
 
作者“前端攻城——usual”

bitsCN.com
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