Created
January 22, 2016 19:06
-
-
Save anonymous/f293830bc47d87f954e4 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 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