Although it does not have much relation with the original doubt, it is worth commenting.
As you said to have seen in a framework, almost absolute certainty (goes that ...) that this was Object Oriented and in such cases an implementation of the PDO needs to have the property in which the instance of the PDO object itself destroyed so that the connection logic works by connecting only once.
The rough way is more or less like this:
abstract class Driver {
protected $conn;
public function getConnection() {
if( $this -> conn === NULL ) {
$this -> connect();
}
return $this -> conn;
}
abstract public function connect();
abstract public function disconnect();
}
class PDO extends Driver {
public function connect() {
$this -> conn = new PDO( /** .. */ );
}
public function disconnect() {
$this -> conn = NULL;
}
}
Note: namespaces , interfaces, or even Object Oriented paradigms have not been taken in to simplify them as much as possible.
Thus, given the vertical and rising Requisite flow, a connection object defined in, say, an Application Controller can be used in an Action Controller or Model without risk of data loss.
And in the case of PDO at least it is very important since some of the operations are performed in the PDO and part in the PDOStatement and any undue re-connection between one step and another can, for example, generate an empty query error.