mysqli.reconnect = ON 更改连接编码?

发布于 2024-10-07 09:28:42 字数 190 浏览 0 评论 0原文

如何防止通过重新连接切换连接编码?我的所有设置都是 utf-8,但是由于我在 cli 的 php.ini 中启用了此功能...我已经测试了任何内容...当我有一个很长的工作脚本时,在脚本的任何点上连接已切换,我的数据错误。当我再次禁用它后,一切都很好。但为什么会这样呢?我应该在 my.cfg 中设置什么样的设置来防止连接编码的这种切换?

干杯 尼克

how to prevent switching the connection encoding by reconnect? Everything of my settings are utf-8, but since I have enabled this function in php.ini of the cli ... I have tested anything ... and when I have a long working script then in any point of the script the connection is switched and I have wrong data. After I have disabled it again, then everything is fine. But why is it so? What kind of settings should I set in my.cfg to prevent this switching of the connection encoding?

Cheers
Nik

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

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

发布评论

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

评论(1

新人笑 2024-10-14 09:28:42

来自 MySQL 文档

如果您使用的 mysql 客户端启用了自动重新连接(不推荐),最好使用 charset 命令而不是 SET NAMES。例如:

 mysql> charset utf8
 Charset changed

charset 命令发出 SET NAMES 语句,还会更改 mysql 在连接断开后重新连接时使用的默认字符集。因此,请发出以下命令:

 mysqli_query('charset utf8');

或者您正在使用的任何字符集(如果不是 UTF8)。这应该可以解决问题。

From the MySQL Docs:

If you are using the mysql client with auto-reconnect enabled (which is not recommended), it is preferable to use the charset command rather than SET NAMES. For example:

 mysql> charset utf8
 Charset changed

The charset command issues a SET NAMES statement, and also changes the default character set that mysql uses when it reconnects after the connection has dropped. Therefore, issue this:

 mysqli_query('charset utf8');

Or whatever charset you're using (if other than UTF8). This should fix the problem.

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