Skip to content

Instantly share code, notes, and snippets.

@IMSoP
Forked from anonymous/Lazy_PDO.php
Last active January 22, 2016 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IMSoP/a8e329e81eacd22a66c1 to your computer and use it in GitHub Desktop.
Save IMSoP/a8e329e81eacd22a66c1 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($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