Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - <?php
- class LazyPdo extends PDO
- {
- private $tenantId;
- private $activeConnection;
- public function __construct($tenantId, Pdo $masterConnection)
- {
- $this->tenantId = $tenantId;
- $this->activeConnection = $masterConnection;
- $this->isMaster = true;
- }
- private function initTenantDb() {
- $connectionDetails = $this->activeConnection->query('SELECT blah');
- $this->activeConnection = new Pdo($connectionDetails);
- $this->isMaster = false
- }
- public function prepare($statement, array $driver_options = array())
- {
- if ($this->isMaster) $this->initTenantDb();
- $this->activeConnection->prepare($statement, $driver_options);
- }
- // all the other Pdo methods with the same if check and delegatation to activeConnection
- }
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment                    
                 
                    