PDOWrapper::getSlave PHP Method

getSlave() protected method

- grab the PDO connection to the slave DB, create it if not there
protected getSlave ( )
    protected function getSlave()
    {
        // if we have not created a slave db connection, create it now
        if (!isset($this->pdo_slave)) {
            // if no slaves were configured, use hardcoded values
            if (!isset($this->config_slaves)) {
                $i = 1;
                while (defined('self::SLAVE' . $i . '_HOST') && constant('self::SLAVE' . $i . '_HOST')) {
                    $this->config_slaves[] = array('driver' => constant('self::SLAVE' . $i . '_DSN_PREFIX'), 'host' => constant('self::SLAVE' . $i . '_HOST'), 'name' => constant('self::SLAVE' . $i . '_NAME'), 'user' => constant('self::SLAVE' . $i . '_USER'), 'password' => constant('self::SLAVE' . $i . '_PASSWORD'), 'port' => constant('self::SLAVE' . $i . '_PORT'));
                    $i++;
                }
            }
            // if no slaves are configured, use the master connection
            if (empty($this->config_slaves)) {
                $this->pdo_slave = $this->getMaster();
            } else {
                $random_slave = $this->config_slaves[array_rand($this->config_slaves)];
                $this->pdo_slave = $this->createConnection($random_slave['driver'], $random_slave['host'], $random_slave['name'], $random_slave['user'], $random_slave['password'], $random_slave['port']);
            }
        }
        return $this->pdo_slave;
    }