php - Scope of PDO used in a function -
i using structure 1 below -
class foo{ . . . function bar($colid){ try{ $dbo = new pdo(get_db_dsn(), get_db_usr(), get_db_pwd()); $pstmt = $dbo->prepare("select * table_name col=:colid"); $pstmt->bindvalue(':colid', $colid); $pstmt->execute(); . . . }catch(pdoexception e){ ... } } i need know if pdo persist till object of foo exists or if destroyed right after end of function's scope.
it garbage collected... if want available after function returns should use foo property store it.
class foo{ . . . var $dbo; function bar($colid){ try{ $this->dbo = new pdo(get_db_dsn(), get_db_usr() get_db_pwd()); . . . }catch(pdoexception e){ ... } }
Comments
Post a Comment