php-mysql乱码问题。

WBOY
Release: 2016-06-06 20:06:28
Original
847 people have browsed it

PHP在连接数据库后都要执行SET NAMES UTF8,防止mysql某个字符集设置的不正确。

今天突然想测试一下,然后尝试把SET NAMES UTF8注释掉,把mysql端的

<code>character_set_connection
character_set_results
character_set_server
character_set_client</code>
Copy after login
Copy after login

统统global设置为utf8

然后的然后,发现插入中文字符又是乱码了,整个人都不好了。

本地的代码和数据库肯定是UTF8

如果按照client->connection->server排查的话是没有问题的,为什么还会出错呢?

回复内容:

PHP在连接数据库后都要执行SET NAMES UTF8,防止mysql某个字符集设置的不正确。

今天突然想测试一下,然后尝试把SET NAMES UTF8注释掉,把mysql端的

<code>character_set_connection
character_set_results
character_set_server
character_set_client</code>
Copy after login
Copy after login

统统global设置为utf8

然后的然后,发现插入中文字符又是乱码了,整个人都不好了。

本地的代码和数据库肯定是UTF8

如果按照client->connection->server排查的话是没有问题的,为什么还会出错呢?

连接设置里,指定utf-8编码

<code><meta http-equiv="Content-Type" content="text/html; charset=?"> </code>
Copy after login
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