Guest User

Untitled

a guest
Aug 5th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. class LazyPdo extends PDO
  3. {
  4.     private $tenantId;
  5.     private $activeConnection;
  6.  
  7.     public function __construct($tenantId, Pdo $masterConnection)
  8.     {
  9.         $this->tenantId = $tenantId;
  10.         $this->activeConnection = $masterConnection;
  11.         $this->isMaster = true;
  12.     }
  13.  
  14.     private function initTenantDb() {
  15.         $connectionDetails = $this->activeConnection->query('SELECT blah');
  16.         $this->activeConnection = new Pdo($connectionDetails);
  17.         $this->isMaster = false
  18.     }
  19.    
  20.     public function prepare($statement, array $driver_options = array())
  21.     {
  22.         if ($this->isMaster) $this->initTenantDb();
  23.         $this->activeConnection->prepare($statement, $driver_options);
  24.     }
  25.    
  26.     // all the other Pdo methods with the same if check and delegatation to activeConnection
  27. }
Advertisement
Add Comment
Please, Sign In to add comment