gpt4 book ai didi

php mysql_connect 资源始终相同

转载 作者:可可西里 更新时间:2023-11-01 08:37:40 26 4
gpt4 key购买 nike

我的 php 脚本有问题,您可以在这里看到: http://codepad.org/F0qhElRC

不为每个子连接打开一个新资源。我已经尝试使用 127.0.0.1 或我的本地网络 IP 但没有任何效果,mysql 中的 max_user_connections 也设置为 0 从 web 打开连接给了我一个不同的网络资源。但在命令行中它使用相同的。

在 mysql_connect 中我指定 new_link 为真,我在 bd 类中放置了一个 __destruct如果 child 被摧毁,关闭连接。关闭连接不会即使在我重新启动脚本后,php 也会打开一个新的。该资源可以是免费的,所以我应该指望这一点,但在 children 身上,我也尝试过 sleep ,但这并不能让它运行一个新的资源。

关于如何调试它有什么建议吗?

基本上我希望每个新脚本或子调用都有一个新连接。

提前致谢。最好的问候,

最佳答案

您已设法省略所有相关代码,但 PHP 中的许多数据库扩展重用当前打开的连接,除非您特别指示它们不要这样做。如果您使用 mysql_connect() ,看看 $new_link 参数:

mysql_connect — Open a connection to a MySQL Server
Report a bug
Description
resource mysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]]]] )

Opens or reuses a connection to a MySQL server.

.

new_link

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. In SQL safe mode, this parameter is ignored.

关于php mysql_connect 资源始终相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6507033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com