mysql pdo连接没有关闭? [英] mysql pdo connection is not closing?

查看:105
本文介绍了mysql pdo连接没有关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的php脚本中,当我在某些PDO mysql连接上执行查询时,在检查mysql日志时,我看不到该连接已关闭.

In my php script, When I am executing query on certain PDO mysql connection, on checking mysql logs, I am not able to see the connection getting closed.

Php代码:

?php
$db = new PDO('mysql:host=HOST;dbname=DB',USER,PASSWORD);
$db->exec("SHOW TABLES");
$db = null;
?>

Mysql日志:

180312 18:31:45 9048429 Connect USER@HOST on DB
        9048429 Query   SHOW TABLES

但是,当我删除查询时,我可以在Mysql日志上看到mysql连接已关闭.

Though, when I remove query, I can see the mysql connection closed on the Mysql log.

php代码:

?php
$db = new PDO('mysql:host=HOST;dbname=DB',USER,PASSWORD);
$db = null;
?>

Mysql日志:

180312 18:33:54 9048515 Connect USER@HOST on DB
        9048515 Quit    

我必须在脚本上明确关闭mysql连接,以防止连接过多.我该怎么做?

I have to close mysql connection explicitly on my script to prevent too many connections. How can I do the same?

推荐答案

使用上述代码,Mysql连接成功关闭.只是退出的连接没有出现在Mysql日志中.

With the above code, Mysql connection was getting closed successfully. Its just that quitting connection was not appearing on Mysql logs.

当我检查Mysql进程列表时,已确认连接成功关闭.

When I checked Mysql processlist, It was verified that connection was closing successfully.

除了上述问题外,如果还有要使用pdo执行的查询语句,则也需要销毁pdo语句处理程序对象以关闭mysql连接,如

In addition to the above problem, if there are query statements to be executed using pdo, then pdo statement handler object need to be destroyed too to close mysql connection as stated in php-mysql-pdo-connection-not-closing-without-destroying-statement-handler.

这篇关于mysql pdo连接没有关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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