Home > Backend Development > PHP Tutorial > php mysql utf-8

php mysql utf-8

WBOY
Release: 2016-06-23 14:36:00
Original
962 people have browsed it

解决从Mysql读取中文时的乱码问题:

建表时先加上default charset=utf8;

插入中文数据之前(Mysql命令提示符下)是用set names gb2312;

在php页面中设置是mysql_query('SET NAMES UTF8');

在php页面(已设定为utf8后)中插入中文数据不会出现乱码,应该插入数据库的时候就是以utf8字符集插入中文数据的故不会出现问题!

在php页面前面不要忘了加上header('content-type;text/html;charset=utf-8');

大家在MySQL命令提示符下想查看数据,中文数据有可能是如下 '?????'

所以大家想查看到正确的中文要与插入中文数据一样使用set names gb2312;

引自:

http://www.cnblogs.com/likwo/archive/2011/08/31/2160699.html

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