Skip to content

Instantly share code, notes, and snippets.

@IMSoP
Forked from anonymous/Closable_PDO.php
Last active January 22, 2016 19:12
Show Gist options
  • Save IMSoP/bb0aecf214071a5b59cb to your computer and use it in GitHub Desktop.
Save IMSoP/bb0aecf214071a5b59cb 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 $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