Home  >  Article  >  Database  >  数据库乱码问题的解决方法_MySQL

数据库乱码问题的解决方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:56:511172browse

  我原来是用的GB2312的编码,考虑到国际化地标准问题,所以现在用的是UTF8编码格式,经过查找相关资料和自己的实际总结,现在显示数据库的中文内容时终于不会出现乱码了。

  解决方法:

  1:建立数据库的时候要用UTF8编码:

  CREATE DATABASE news DEFAULT CHARSET=UTF8 。

  2:建立数据表的时候也要用UTF8编码:

  CREATE TABLE xinwen

  (

  title varchar(20) not null

  )default charset=utf8;

  3:用PHP操作数据库的时候先要把插入数据库的内容进行UTF8编码:

  mysql_query('set names utf8');

  4:在PHP页面开始时加上:

  header('content-type:text/html;charset=utf-8');

  5:浏览权的页面设置的编码类型也要换成UTF8编码格式。

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