Mysql SET NAMES UTF8 - 如何摆脱?

发布于 2024-08-29 11:15:50 字数 530 浏览 3 评论 0原文

在一个非常繁忙的 PHP 脚本中,我们在开头调用“设置名称 utf8”,它设置 mysql 应该解释并将数据从服务器发送回客户端的字符集。

http://dev.mysql.com/doc/refman/ 5.0/en/charset-applications.html

我想摆脱它,所以我在我们的服务器 ini 文件中设置了 default-character-set=utf8 。 (参见上面的链接)

该设置似乎有效,因为相关的服务器参数是: '字符集客户端','utf8' '字符集连接', 'utf8' '字符集数据库', 'latin1' '字符集文件系统','二进制' '字符集结果', 'utf8' '字符集服务器', 'latin1' '字符集系统', 'utf8' 但经过此更改并注释掉设置名称 utf8 调用后,数据仍然开始出现乱码。

请指教....

In a very busy PHP script we have a call at the beginning to "Set names utf8" which is setting the character set in which mysql should interpret and send the data back from the server to the client.

http://dev.mysql.com/doc/refman/5.0/en/charset-applications.html

I want to get rid of it so I set default-character-set=utf8 In our server ini file. (see link above)

The setting seems to be working since the relevant server parameters are :
'character_set_client', 'utf8'
'character_set_connection', 'utf8'
'character_set_database', 'latin1'
'character_set_filesystem', 'binary'
'character_set_results', 'utf8'
'character_set_server', 'latin1'
'character_set_system', 'utf8'
But after this change and commenting out set names utf8 call still the data starts to come out garbled.

Please advise....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£烟消云散 2024-09-05 11:15:50

设置PHP和MySQL之间连接的编码是PHP的工作;我不认为 MySQL 设置会影响这一点。

我真的建议在应用程序中保留一些代码以将连接字符集设置为 UTF-8。应用程序需要确保编码为 UTF-8,因为它可能会告诉 Web 浏览器其页面是 UTF-8,如果这些不匹配,则会出现问题。

由于决定字符集已经是应用程序责任的一部分,因此您不妨让应用程序指定数据库连接字符集,而不是将其作为部署问题,并且在安装应用程序时又会出现错误。一个新的服务器。

不过,我个人会使用 mysql_set_charset 来执行此操作,而不是 <代码>设置名称。

同样,如果应用程序中有用于创建架构的代码,请确保该代码告诉 MySQL 将表设为 UTF-8,而不是保留数据库的默认设置,从而给自己带来另一个需要担心的部署问题。

Setting the encoding of the connection between PHP and MySQL is PHP's job; I don't think the MySQL setting will affect that.

I'd really recommend keeping some code in the application to set the connection character set to UTF-8. The application needs to ensure that the encoding is UTF-8, because it will presumably be telling web browsers its pages are UTF-8, and if those don't match you've got problems.

Since it's already part of the application's responsibility to decide the charset, you might as well make the application the one to specify the database connection character set, rather than leave it as a deployment issue and one more thing to get wrong when installing the app on a new server.

However I would personally use mysql_set_charset to do this rather than SET NAMES.

Similarly, if the application has code in it to create the schema, make sure that code tells MySQL to make the tables UTF-8, rather than leaving it up to the database's default settings and giving yourself another deployment issue to worry about.

笑咖 2024-09-05 11:15:50

Skip-character-set-client-handshake

但我不认为设置名称查询的工作量太大。你的问题不知从何而来。并会限制你的数据库功能

skip-character-set-client-handshake

but I don't think that Set names query is too much job. You've got your problem out of nowhere. And going to limit your database functionality

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文