我正在使用如下结构 -
class foo{
.
.
.
function bar($colID){
try{
$dbo = new PDO(get_db_DSN(),
get_db_USR(),
get_db_PWD());
$pstmt = $dbo->prepare("SELECT * FROM table_name WHERE col=:colID");
$pstmt->bindValue(':colID', $colID);
$pstmt->execute();
.
.
.
}catch(PDOException e){
...
}
}
我需要知道 PDO 是否会持续存在,直到 foo
的对象存在,或者它是否会在函数作用域结束后立即被销毁。
最佳答案
在$dbo
之后将被“销毁”。
Variable containers get destroyed when the "refcount" reaches zero. The "refcount" gets decreased by one when any symbol linked to the variable container leaves the scope (e.g. when the function ends) or when unset() is called on a symbol.
关于php - 函数中使用的 PDO 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16681528/