Skip to content

Instantly share code, notes, and snippets.

Created January 22, 2016 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/f293830bc47d87f954e4 to your computer and use it in GitHub Desktop.
Save anonymous/f293830bc47d87f954e4 to your computer and use it in GitHub Desktop.
<?php
class Lazy_PDO
{
private $pdo;
private $dsn, $username, $password, $options;
public function __construct($dsn, $username, $password, $options) {
$this->dsn = $dsn;
$this->username = $username;
$this->password = $password;
$this->options = $options;
}
public function openConnection() {
$this->pdo = new PDO($dsn, $username, $password, $options);
}
public function closeConnection() {
unset($this->pdo);
}
public function __call($func, $args) {
if ( is_null($this->pdo) ) {
$this->openConnection();
}
return call_user_func_array([parent::class, $func], $args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment