Home  >  Article  >  Backend Development  >  Solve phpmyadmin garbled characters and support gb2312 and utf-8_PHP tutorial

Solve phpmyadmin garbled characters and support gb2312 and utf-8_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:00:27742browse

解决phpmyadmin 乱码,支持gb2312和utf-8

    群里很多PHP爱好者一直受phpmyadmin的乱码问题困扰.我自从有了mysql-front后,我就很少使用phpmyadmin了.但每次连接远程主机,就比较慢.造成操作不便.今天有点时间,就下了最新的版本来研究.

首先说明我的数据库使用情况:

phpmyadmin 版本2.7.0-pl1
(如果你使用其它版本,可能会有所不同,请对照修改或者到 这里下载 phpmyadmin 2.7.0-pl1)

mysql版本MySQL 5.0.11-beta-nt

我在以前是使用GB2312编码方式,直接写入数据库的,字符集是mysql默认的latin1

PHP5以后我写的程序都改用UTF-8编码方式了,也是直接读写的.所以字符集也应试是mysql默认的latin1

我在用PHP操作数据时 没有 使用过以下语句:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

好,开始吧.

 把下载的ZIP包解压到www目录后打开文件夹...好久不见,配置文件名都从config.inc.php改成了config.default.php .

我修改了以下代码:

31行
$cfg['PmaAbsoluteUri'] = 'http://localhost/phpMyAdmin-2.7.0-pl1/';

45行
$cfg['blowfish_secret'] = 'this';

71行
$cfg['Servers'][$i]['auth_type']     = 'cookie';    // Authentication method (config, http or cookie based)?

接着,浏览器打开http://localhost/phpMyAdmin-2.7.0-pl1/ 使用root登录.language是默认的chinese simplified(zh-utf-8)

浏览一个UTF-8的表.乱码.

查看了html源代码,charset=utf-8

查看他的语言选择文件libraries/select_lang.lib.php

263行 'utf-8'        => 'utf8',

我用的是默认的latin1 所以,这里应试改成latin1.改好保存,刷新.成功

转到一个以前用GB2312编码录入的库.是乱码.

退出.以chinese simplified(zh-gb2312)登录.到处看.乱码.

和上面一样找到libraries/select_lang.lib.php

250行 'gb2312'        => 'gb2312',

把gb2312改为latin1.保存,刷新.却不行.还是一样.

很纳闷.查看了html源代码,charset还是utf-8.不对呀,应试是GB2312才正常.

无意中在首页的language下拉菜单中,发现没有登录时的chinese simplified(zh-gb2312)这一栏.(下图)

不解,仔细一对,列表项都是utf-8结束的.问题应试在这.

找libraries/select_lang.lib.php里对应的zh-gb2312,在它后面加上一个"-utf-8"

这回有了.查看了html源代码,charset是GB2312了.

如何在两种语言转换呢?
我试着回到UTF-8编码的表.没错,是乱码.

转到首页.language下拉菜单中选择zh-utf-8.再看看,OK了.

试着修改,添加新数据.都没再有乱码了.

结束:我的思路是以html的charset对照mysql的charset.

最后提醒:

如果你操作表时使用过以下语句:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

那么你修改时libraries/select_lang.lib.php可能会有所不同.多试试几种方式.会有不一样的收获.

Please indicate the source for reprinting as www.phpv.net

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317103.htmlTechArticleSolve phpmyadmin garbled code, support gb2312 and utf-8 Many PHP enthusiasts in the group have been troubled by phpmyadmin garbled code problem. Since I got mysql-front, I rarely use phpmyadmin. But every time I connect...
Statement:
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