-
-
Save IMSoP/a8e329e81eacd22a66c1 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($this->dsn, $this->username, $this->password, $this->options); | |
} | |
public function closeConnection() { | |
unset($this->pdo); | |
} | |
public function __call($func, $args) { | |
if ( is_null($this->pdo) ) { | |
$this->openConnection(); | |
} | |
return $this->pdo->$func($args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment