PHP mysql_connect资源始终相同 [英] php mysql_connect resource is allways the same

查看:93
本文介绍了PHP mysql_connect资源始终相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP脚本女巫遇到了问题,您可以在这里看到: http://codepad.org/F0qhElRC

I'm having a problem my php script witch you can see here: http://codepad.org/F0qhElRC

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

Is not opening a new resource for each connection from a child. Already I tryed using 127.0.0.1 or my local network IP but nothing worked, also max_user_connections in mysql is set to 0 opening a connection from web gives me a different resource for the web. But in the command line it uses the same.

在mysql_connect中,我指定new_link为true,我在bd类中放置了一个__destruct 如果孩子被摧毁,则关闭连接.关闭连接不会 即使我重新启动脚本,PHP也会打开一个新的PHP.该资源可能是免费的,所以我应该 依靠这一点,但在孩子们中,我也尝试过睡觉,但这并不能使它运行 一种新资源.

In mysql_connect I specified new_link to be true, I placed a __destruct in the bd class to close the connection if the child get's destroyed. Closing the connection does not make php open a new one even after I restart the script. The resource could be free and so I should count on that but in the childs I also have tryed placing a sleep but that doesn't make it run a new resource.

有人怀疑如何调试它吗?

Any sugestions on how to debug this?

基本上,我为每个新的脚本或子调用都希望有一个新的conn.

Basically I whant a new conn for every new script or child call.

先谢谢了. 最好的问候,

Thanks in advance. Best regards,

推荐答案

您已经设法省略了所有相关代码,但是PHP中的许多数据库扩展都重用了当前打开的连接,除非您明确指示不要这样做.如果您使用的是 mysql_connect(),请查看$new_link参数:

You've managed to omit all the relevant code, but many database extensions in PHP reuse currently open connections unless you specifically instruct them not to do so. If you are using mysql_connect(), have a look at the $new_link parameter:

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

new_link

如果使用相同的命令再次调用mysql_connect() 参数,将没有新的链接 建立,但链接 已经打开的链接的标识符 将被退回. new_link 参数修改此行为,并 使mysql_connect()总是打开一个 新的链接,即使mysql_connect()是 之前用相同的方式调用 参数.在SQL安全模式下, 参数将被忽略.

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资源始终相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆