replyIf you are using phpstudy and have a similar problem to the original poster, how should you solve it? When the SQL statement is written in PHP and run, Chinese garbled characters appear when browsing the data; when the SQL statement is run on the web page, the Chinese characters are also garbled.
看你的数据库表里面有正常的中文,那就试插入数据的时候出现的问题。统一字符编码格式:
确保数据库,表,字段设置的都是
utf-8
确保连接数据库的时候设置字符集是
utf-8
确保程序文件是
utf-8
确保mysql安装程序的配置文件设置字符
utf-8
设置字符集试试
我找到问题关键了,下面两位回答的我都试过了,不起效果,问题出在mysql.ini配置少了一句话default-character-set = utf8 ,我是安装wampserver后用这个软件自己安装的mysql他的mysql.ini没有那句话,,而且如果加入这句话位置也不能乱加,必须加在我图片指出的位置![](http://img.php.cn/upload/image/000/000/000/a0c99035b6c2b349e17f28fd90cbb524-0.png)
用show variables like 'character_set_%;查看修改ini文件后的字符编码如下图
![](http://img.php.cn/upload/image/000/000/000/a0c99035b6c2b349e17f28fd90cbb524-2.png)
你要设置mysql编码 执行sql "set names utf8"