Skip to content

Instantly share code, notes, and snippets.

Created January 22, 2016 18:58
Show Gist options
  • Save anonymous/6d970203079ee87fe452 to your computer and use it in GitHub Desktop.
Save anonymous/6d970203079ee87fe452 to your computer and use it in GitHub Desktop.
<?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 call_user_func_array([parent::class, $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