mysql pdo 关闭,mysql pdo连接没有关闭?

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 Code:

?php

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

$db->exec("SHOW TABLES");

$db = null;

?>

Mysql logs:

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

9048429 Query SHOW TABLES

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

php code:

?php

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

$db = null;

?>

Mysql log:

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

9048515 Quit

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

解决方案

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

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值