Returns the Couchbase bucket for this query.

@param Connection $db Couchbase connection.

@return Bucket bucket instance.
@throws Exception
@throws \yii\base\InvalidConfigException
437673
public function getBucket($db = null)
    {
        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;

        if ($db === null) {
            $db = $modelClass::getDb();
        }

        if ($this->select === null) {
            $bucketName = $db->quoteBucketName($modelClass::bucketName());

            $primaryModel = $this->primaryModel ?: ActiveRecord::className();

            $primaryKey = $primaryModel::primaryKey()[0];
            $primaryKey = $db->quoteColumnName($primaryKey);

            $this->select = "meta($bucketName).id AS $primaryKey, $bucketName.*";
        }

        if ($this->from === null) {
            $this->from = $modelClass::bucketName();
        }

        return $db->getBucket($this->from);
    }
576037
private function getDatabasePlatform(Connection $connection)
    {
        try {
            return $connection->getDatabasePlatform();
        } catch (DriverException $driverException) {
            throw new DBALException(
                'An exception occured while establishing a connection to figure out your platform version.' . PHP_EOL .
                "You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
                'For further information have a look at:' . PHP_EOL .
                'https://github.com/doctrine/DoctrineBundle/issues/673',
                0,
                $driverException
            );
        }
    }
634964
public function getCollection($db = null)
    {
        if ($db === null) {
            $db = Yii::$app->get('mongodb');
        }

        return $db->getCollection($this->from);
    }
638880
public function db($db = null)
    {
        if ($db === null)
        {
            return $this->_db;
        }
        $this->_db = $db;

        return $this;
    }
463302
public function export_dbconfig() {
        $cfg = new stdClass();
        $cfg->dbtype    = $this->get_dbtype();
        $cfg->dblibrary = $this->get_dblibrary();
        $cfg->dbhost    = $this->dbhost;
        $cfg->dbname    = $this->dbname;
        $cfg->dbuser    = $this->dbuser;
        $cfg->dbpass    = $this->dbpass;
        $cfg->prefix    = $this->prefix;
        if ($this->dboptions) {
            $cfg->dboptions = $this->dboptions;
        }

        return $cfg;
    }
1106283
private function getConfigDB(ConfigInterface $config): ConfigInterface
    {
        // get current connection
        $connection = $this->getConnection();
        // Get config of required connection
        $config_db = $config->get($connection);
        try {
            if (null === $config_db) {
                throw new Exception("Connection \"$connection\" is not found in database config");
            }
        } catch (Exception $e) {
            // __constructor
        }
        return $config_db;
    }
1026152
public static function getInstance($db = null) {

        if (empty(self::$instance)) {

            if (is_null($db)) {
                throw new \RuntimeException('Empty params');
            }

            self::$instance = new Acl($db);
        }

        return self::$instance;
    }
779049
public function getDbConnection()
    {
        if (!Yii::app()->hasComponent($this->connectionID)) {
            throw new CException(sprintf('Connection component "%s" does not exist.', $this->connectionID));
        }
        $db = Yii::app()->getComponent($this->connectionID);
        if (!$db instanceof CDbConnection) {
            throw new CException(sprintf(
                'Connection component "%s" is not an instance of CDbConnection.',
                $this->connectionID
            ));
        }
        return $db;
    }
438364
public function set_connection($db)
	{
		if ( ! $db instanceof \Database_Connection)
		{
			// Get the database instance
			$db = \Database_Connection::instance($db);
		}
		$this->_connection = $db;

		return $this;
	}
1042855
public static function getConection() : \PDO
    {
        if (self::$instance === null) {
            $con = self::findData();
            self::$instance = new \PDO("mysql:host=".$con['HOST'].";dbname=".$con['DBNAME'], $con['USER'], $con['PASS']);
            self::$instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
                
        }
        return self::$instance;
    }
1161492
public static function build(string $connectionName = null) : Connection
    {
        $configs = Application::current()->config('database');
        $connectionName = $connectionName ?: $configs['default'];

        if (!isset($configs[$connectionName])) {
            throw new \Exception("Unknown database connection: '$connectionName'");
        }

        if (!isset(self::$connections[$connectionName])) {
            $connectionClass = $configs[$connectionName]['driver'];
            $options = $configs[$connectionName]['options'];
            self::$connections[$connectionName] = new $connectionClass($options);
        }

        return self::$connections[$connectionName];
    }
670513
public static function getInstance($db)
    {
        if (!isset(self::$instances[$db])) {
            $config = config('database.' . $db);
            if (!$config) {
                throw new RuntimeException('Not found database config [' . $db . '], Please checking file config/database.php');
            }

            switch ($config['driver']) {
                case 'mysql':
                    self::$instances[$db] = new MysqlConnection($config);
                    break;
            }
        }

        return self::$instances[$db];
    }
122975
static public function getInstance($db, $singleton = true)
    {
        static $cache = array();

        if (!isset($cache[$db]) || !$singleton) {
            $obj    = new self();
            $config = config('ssdb.' . $db);
            if (!$config) {
                throw new \RuntimeException('ssdb config error.');
            }
            $obj->host = $config['host'];
            $obj->port = $config['port'];
            $obj->connect($obj->host, $obj->port);
            $cache[$db] = $obj;
        }

        return $cache[$db];
    }
150770
public static function connectDb() {
        if 
            (!isset(self::$dbLink)) {
            $dbParams = self::getDatabaseParameters();
            self::validateDbParameters($dbParams);
            $dbParamsSan = self::sanitizeDbParameters($dbParams);
            $config = new Configuration();
            self::$dbLink = DriverManager::getConnection($dbParamsSan, $config);
        }
        
        return self::$dbLink;
    }
710006
public static function load($db = null)
    {
        if (!isset(self::$_instance)) {
            self::$_instance = new Validator($db);
        }

        return self::$_instance;
    }
920240
protected function selectBucket($name, $password = '')
    {
        $this->open();

        try {
            $bucket = $this->cluster->openBucket($name, $password);
        }
        catch (\Exception $e) {
            throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
        }

        return Yii::createObject([
            'class'  => 'matrozov\couchbase\Bucket',
            'db'     => $this,
            'name'   => $name,
            'bucket' => $bucket,
        ]);
    }
1309784
public static function getDbo($config = array(), $cname = '')
	{
		// empty instance of db
		$db = App::get('db');

		// make sure we have a group object
		if (!$group = Group::getInstance(\Request::getString('cn', $cname)))
		{
			return $db;
		}

		// make sure we are a super group
		if (!$group->isSuperGroup())
		{
			return $db;
		}

		// load super group db config if not passed in
		if (empty($config))
		{
			// build path to config file
			$uploadPath = \Component::params( 'com_groups' )->get('uploadpath');
			$configPath = PATH_APP . DS . trim($uploadPath, DS) . DS . $group->get('gidNumber') . DS . 'config' . DS . 'db.php';

			// make sure file exists
			if (!file_exists($configPath))
			{
				return $db;
			}

			// include config
			$config = include $configPath;
		}

		// return instance of db
		return \Hubzero\Database\Driver::getInstance($config);
	}