php+mysql显示乱码的个人总结
生活随笔
收集整理的這篇文章主要介紹了
php+mysql显示乱码的个人总结
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
說起亂碼,我就很討厭的,每次亂碼都要花費我很長的時間去找原因,而網上搜索的答案很多,很亂,很難判斷哪個答案是適合自己系統(tǒng)的,現(xiàn)在就把我在php+mysql中文顯示正常的代碼給貼出來,希望對大家有所幫助。 我的系統(tǒng)是centos5.5,mysql是5.5.20?, php是5.3.10 cat /etc/sysconfig/i18n
LANG="zh_CN.GBK" vi /etc/my.cnf 分別在如下幾項添加字符集:
[client]
default-character-set=gbk [mysqld]
character_set_server = gbk? ?網上很多文章都是在這里添加?default-character-set=gbk,剛開始我也照網上的資料做,每次啟動mysql都是報錯的,后來通過查找資料才知道m(xù)ysql的高級版本不用default-character-set=gbk,而是用character_set_server = gbk
[mysql]
default-character-set=gbk
修改后保存。大家根據自己設置的方式重啟mysql數(shù)據庫 mysql -uroot -p mysql> show variables like 'char%';
+--------------------------+----------------------------------+
| Variable_name??????????? | Value??????????????????????????? |
+--------------------------+----------------------------------+
| character_set_client???? | gbk????????????????????????????? |
| character_set_connection | gbk????????????????????????????? |
| character_set_database?? | gbk????????????????????????????? |
| character_set_filesystem | binary?????????????????????????? |
| character_set_results??? | gbk????????????????????????????? |
| character_set_server???? | gbk????????????????????????????? |
| character_set_system???? | utf8???????????????????????????? |
| character_sets_dir?????? | /usr/local/mysql/share/charsets/ |
+--------------------------+---------------------------------- 這是修改后的mysql數(shù)據庫編碼 在php中的mysql_connect(...);mysql_select_db(...);后插入mysql_query("set names 'GBK'");防止在php轉碼的時候出現(xiàn)亂碼 希望對大家在mysql出現(xiàn)亂碼的時候有所幫助
LANG="zh_CN.GBK" vi /etc/my.cnf 分別在如下幾項添加字符集:
[client]
default-character-set=gbk [mysqld]
character_set_server = gbk? ?網上很多文章都是在這里添加?default-character-set=gbk,剛開始我也照網上的資料做,每次啟動mysql都是報錯的,后來通過查找資料才知道m(xù)ysql的高級版本不用default-character-set=gbk,而是用character_set_server = gbk
[mysql]
default-character-set=gbk
修改后保存。大家根據自己設置的方式重啟mysql數(shù)據庫 mysql -uroot -p mysql> show variables like 'char%';
+--------------------------+----------------------------------+
| Variable_name??????????? | Value??????????????????????????? |
+--------------------------+----------------------------------+
| character_set_client???? | gbk????????????????????????????? |
| character_set_connection | gbk????????????????????????????? |
| character_set_database?? | gbk????????????????????????????? |
| character_set_filesystem | binary?????????????????????????? |
| character_set_results??? | gbk????????????????????????????? |
| character_set_server???? | gbk????????????????????????????? |
| character_set_system???? | utf8???????????????????????????? |
| character_sets_dir?????? | /usr/local/mysql/share/charsets/ |
+--------------------------+---------------------------------- 這是修改后的mysql數(shù)據庫編碼 在php中的mysql_connect(...);mysql_select_db(...);后插入mysql_query("set names 'GBK'");防止在php轉碼的時候出現(xiàn)亂碼 希望對大家在mysql出現(xiàn)亂碼的時候有所幫助
轉載于:https://blog.51cto.com/flyfishes/826480
總結
以上是生活随笔為你收集整理的php+mysql显示乱码的个人总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IMail Server 8.22安装、
- 下一篇: POJ-2584 T-Shirt Gum