问题描述
与MySQLi相比,关于PDO的问题很简单.
Just a rather simple question with regards to PDO compared to MySQLi.
使用MySQLi,可以关闭连接:
With MySQLi, to close the connection you could do:
$this->connection->close();
但是对于PDO,它指出您使用以下方法打开连接:
However with PDO it states you open the connection using:
$this->connection = new PDO();
但要关闭连接,请将其设置为null
.
but to close the connection you set it to null
.
$this->connection = null;
这是正确的吗,这实际上会释放PDO连接吗? (我知道它的确是设置为null
的方式.)我的意思是,对于MySQLi,您必须调用一个函数(close
)来关闭连接. PDO与= null
一样容易断开吗?还是有关闭连接的功能?
Is this correct and will this actually free the PDO connection? (I know it does as it is set to null
.) I mean with MySQLi you have to call a function (close
) to close the connection. Is PDO as easy as = null
to disconnect? Or is there a function to close the connection?
推荐答案
根据文档,您是正确的( http ://php.net/manual/en/pdo.connections.php ):
According to documentation you're correct (http://php.net/manual/en/pdo.connections.php):
请注意,如果将PDO对象初始化为持久连接,它将不会自动关闭连接.
Note that if you initialise the PDO object as a persistent connection it will not automatically close the connection.
这篇关于PDO关闭连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!