Home  >  Article  >  Database  >  php-向mysql写入中文数据时不显示或显示乱码

php-向mysql写入中文数据时不显示或显示乱码

WBOY
WBOYOriginal
2016-06-06 09:45:201066browse

mysqlphp中文数据库乱码

今天写php,向mysql插入数据时,无法显示中文或显示乱码,怎么解决?
已经设定了字符集:
mysql_query('SET NAMES utf8');
sql语句:
mysql_query("INSERT INTO user (username) VALUES ('庞统')");

数据库表结构:
username varchar(20) utf8_general_ci

而且mysql的配置文件my.ini里我也改了,在
[mysql] [mysqld]后面加上了
default-character-set=utf8

请问如何解决?
补充一点:
把mysql的编码换成gbk,
mysql_query('SET NAMES gbk');这条也改成gbk;
则在phpMyadmin里可以显示中文了,但在mysql客户端还是不能显示

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