-
-
Save IMSoP/bb0aecf214071a5b59cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Closable_PDO | |
{ | |
private $pdo; | |
public function __construct($dsn, $username, $password, $options) { | |
$this->pdo = new PDO($dsn, $username, $password, $options); | |
} | |
public function __call($func, $args) { | |
if ( is_null($this->pdo) ) { | |
throw new Exception("Attempt to run $func on a closed PDO handle."); | |
} else { | |
return $this->pdo->$func($args); | |
} | |
} | |
public function closeConnection() { | |
unset($this->pdo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment