gpt4 book ai didi

php - 是否需要关闭 PDO 连接

转载 作者:IT王子 更新时间:2023-10-28 23:47:04 27 4
gpt4 key购买 nike

我注意到 PDO 没有关闭功能。我应该关闭连接还是 PDO 不需要?

最佳答案

Upon successful connection to the database, an instance of the PDO class is returned to your script. The connection remains active for the lifetime of that PDO object. To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted--you do this by assigning NULL to the variable that holds the object. If you don't do this explicitly, PHP will automatically close the connection when your script ends.

http://php.net/manual/en/pdo.connections.php

所以答案是否定的,除非出于任何原因需要在脚本执行期间显式关闭连接,否则您不需要执行任何操作,在这种情况下,只需将您的 PDO 对象设置为 null。

关于php - 是否需要关闭 PDO 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15444748/

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