Return database slave
@return \Sonic\Resource\Db
760903
public static function &_getDbSlave ()
	{
		
		// Get the default slave
		
		$obj	=& self::_getResource ('db-slave');
		
		// Failing that try to get a random slave
		
		if (!$obj)
		{
			
			$obj	=& self::_getRandomDbResource ('db-slave');
			
			// Default to database resource if no valid slave
		
			if (!$obj)
			{
				$obj =& self::_getResource ('db');
			}
			
		}
		
		// Return database connection
		
		return $obj;
		
	}
80112
public function _db(){
        $server = $this->server;

        $dsn = "{$server['driver']}:{$server['dbname']}";

        return Pool::object($dsn,'\\PDO',[
            $dsn,$server['user'],$server['pass']
        ]);
    }
916392
protected function db(): Database
    {
        $conn = app(Pool::class)->getConnection();
        $database = $conn->defaultDatabase;

        return $conn->getRawConnection()->$database;
    }
271839
protected function getDb2()
    {
        if (!$this->db2 instanceof Adapter) {
            $config = Zend_Controller_Front::getInstance()->getParam('bootstrap');
            $resources = $config->getOption('resources');
            $dbConfig = array(
                'driver'   => $resources['db']['adapter'],
                'hostname' => $resources['db']['params']['host'],
                'database' => $resources['db']['params']['dbname'],
                'username' => $resources['db']['params']['username'],
                'password' => $resources['db']['params']['password'],
                'charset'  => $resources['db']['params']['charset'],
            );

            $this->db2 = new Adapter($dbConfig);
        }

        return $this->db2;
    }
926429
public function syncDb() {
    $local_alias = '@' . $this->getConfigValue('drush.aliases.local');
    $remote_alias = '@' . $this->getConfigValue('drush.aliases.remote');

    $task = $this->taskDrush()
      ->alias('')
      ->drush('cache-clear drush')
      ->drush('sql-sync')
      ->arg($remote_alias)
      ->arg($local_alias)
      ->option('--target-dump', sys_get_temp_dir() . '/tmp.target.sql.gz')
      ->option('structure-tables-key', 'lightweight')
      ->option('create-db');

    if ($this->getConfigValue('drush.sanitize')) {
      $task->drush('sql-sanitize');
    }

    $task->drush('cr');
    $task->drush('sqlq "TRUNCATE cache_entity"');

    $result = $task->run();

    return $result;
  }
352610
public function connection()
    {
        if (!is_object($this->db)) {
            $this->db = new \MysqliDb();
            $this->db->addConnection($this->dbName, $this->database);
        }

        return $this;
    }
1098690
public function getDb()
    {
        if ($this->_db === NULL and $this->getConfig('main/db/engine')) {
            $this->_db = new Db();
        }

        return $this->_db;
    }
1373253
public function getDatasource()
    {
        $adapter = $this->getAdapter();

        if ($adapter) {
            return $adapter;
        }

        $engine = $this->dsn->engine;

        return 'Database/' . ucfirst($engine);
    }
277793
public function getMainDB()
    {
        if ($this->main_database === null &&
            ($this->isOperationModeCLI() || $this->isOperationModeStandalone())
        ) {
            $this->registerMainDatabase();
        }
        return $this->main_database;
    }
191123
public function getDatabase($connectionName = 'default')
    {
        if ($this->databases->containsKey($connectionName)) {
            return $this->databases->get($connectionName);
        }

        $configuration = $this->getConfiguration($connectionName);
        $database = $this->getConnection($connectionName);

        $database->DBOpen(
            $configuration->getDatabase(),
            $configuration->getUser(),
            $configuration->getPassword()
        );

        $this->databases->set($connectionName, $database);

        return $this->databases->get($connectionName);
    }
492012
public static function getDBO() {
		if (!empty(self::$db)) {
			return self::$db;
		}
		BLog::addToLog('[BFactory] Connecting to the database "' . MYSQL_DB_HOST . '"...');
		self::$db = BMySQL::getInstanceAndConnect();
		if (empty(self::$db)) {
			BLog::addToLog('[BFactory] Could not connect to the MySQL database!', LL_ERROR);
			return NULL;
		}
		return self::$db;
	}
171474
protected function getDb()
    {
        if (isset($this->_db)) {
            return $this->_db;
        } else {
            if (($db = Yii::app()->getComponent($this->connectionID)) === null) {
                throw new CException(sprintf(
                    'Failed to get database connection. Component %s not found.',
                    $this->connectionID
                ));
            }
            return $this->_db = $db;
        }
    }
225467
private function slaveQueryBuilder()
    {
        /** @var Connection $connection */
        $connection = $this->em->getConnection();
        if ($connection instanceof MasterSlaveConnection) {
            // Prefer a slave connection if available.
            $connection->connect('slave');
        }

        return new QueryBuilder($connection);
    }
462978
public function getDBO()
	{
		$db = \App::get('db');

		// Test the connection
		if (!$db->connected())
		{
			$this->log('PDO connection failed', 'error');
			return false;
		}

		// Check for the existance of the migrations table
		$tables = $db->getTableList();
		$prefix = $db->getPrefix();
		$tableset = false;

		if (in_array('migrations', $tables))
		{
			$this->setTableName('migrations');
			$tableset = true;
		}

		if (in_array($prefix . 'migrations', $tables))
		{
			if ($tableset)
			{
				$this->log('Tables `migrations` and `' . $prefix . 'migrations` both exist', 'error');
				return false;
			}

			$this->setTableName('#__migrations');
			$tableset = true;
		}

		if (!$tableset)
		{
			if ($this->createMigrationsTable($db) === false)
			{
				return false;
			}
		}

		// Add a callback so that a migration can update $this in real time if necessary
		$this->registerCallback('migration', $this);

		return $db;
	}
994859
public function get_dbh()
    {
        if (!$this->db) {
            $this->db = rcube_db::factory(
                $this->config->get('db_dsnw'),
                $this->config->get('db_dsnr'),
                $this->config->get('db_persistent')
            );

            $this->db->set_debug((bool)$this->config->get('sql_debug'));
        }

        return $this->db;
    }
95477
public function database()
    {
        if (is_null($this->database)) {
            $this->database = app(Database::class);
        }

        return $this->database;
    }
1106725
public function getResource(): object
    {
        \mysqli_report(MYSQLI_REPORT_ALL);

        return new mysqli(
            $this->options['host'],
            $this->options['user'],
            $this->options['password'],
            $this->options['database'],
            $this->options['port']
        );
    }