Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. <?php
  2.  
  3. class Lazy_PDO
  4. {
  5. private $pdo;
  6. private $dsn, $username, $password, $options;
  7.  
  8. public function __construct($dsn, $username, $password, $options) {
  9. $this->dsn = $dsn;
  10. $this->username = $username;
  11. $this->password = $password;
  12. $this->options = $options;
  13. }
  14.  
  15. public function openConnection() {
  16. $this->pdo = new PDO($this->dsn, $this->username, $this->password, $this->options);
  17. }
  18.  
  19. public function closeConnection() {
  20. unset($this->pdo);
  21. }
  22.  
  23. public function __call($func, $args) {
  24. if ( is_null($this->pdo) ) {
  25. $this->openConnection();
  26. }
  27.  
  28. return $this->pdo->$func($args);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement