Home  >  Article  >  Database  >  Ubuntu PHP插入MySQL数据库乱码问题的解决

Ubuntu PHP插入MySQL数据库乱码问题的解决

WBOY
WBOYOriginal
2016-06-07 16:51:39967browse

环境:Ubuntu Linux以下方法经本人试验过,确实能解决Ubuntu PHP插入MySQL数据库乱码问题。1.数据库尽量使用utf8存储(修改/etc/

环境:Ubuntu Linux
以下方法经本人试验过,,确实能解决Ubuntu PHP插入MySQL数据库乱码问题。

1.数据库尽量使用utf8存储(修改/etc/my.cnf,在[mysqld]段加上default-character-set=utf8)(已有的数据库,先转成UTF8格式)

2.PHP程序在查询数据库之前,执行mysql_query(“set names xxxx”);其中xxxx是你网页的编码(charset=xxxx),如果网页中charset=utf8,则xxxx=utf8,如果网页中charset=gb2312,则xxxx=gb2312

几乎所有WEB程序,都有一段连接数据库的公共代码,放在一个文件里,在这文件里,加入mysql_query(“set names”)就可以了。

3.PHPMyAdmin不需要做改动。

4.需要注意的是,为保证网页实际编码(Windows保存对话框里的编码)和他声明的编码(charset=?)是一致的,请用DW之类的工具做网页.

linux

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