Get a suitable database. Either the provided database argument,
or when null, the source database. If source database is also null,
the default database is returned.
@return Wedeto\DB\DB A suitable database
174923
public function getDB($db = null)
    {
        if (null !== $db && !($db instanceof DB))
            throw new InvalidTypeException("Invalid database");
        return $db ?: $this->_source_db ?: DI::getInjector()->getInstance(DB::class);
    }
1363886
protected function getDatabaseConfig()
    {
        /** @skipUpgrade */
        $databaseConfig = [
            "type" => Environment::getEnv('SS_DATABASE_CLASS') ?: 'MySQLDatabase',
            "server" => Environment::getEnv('SS_DATABASE_SERVER') ?: 'localhost',
            "username" => Environment::getEnv('SS_DATABASE_USERNAME') ?: null,
            "password" => Environment::getEnv('SS_DATABASE_PASSWORD') ?: null,
        ];

        // Set the port if called for
        $dbPort = Environment::getEnv('SS_DATABASE_PORT');
        if ($dbPort) {
            $databaseConfig['port'] = $dbPort;
        }

        // Set the timezone if called for
        $dbTZ = Environment::getEnv('SS_DATABASE_TIMEZONE');
        if ($dbTZ) {
            $databaseConfig['timezone'] = $dbTZ;
        }

        // For schema enabled drivers:
        $dbSchema = Environment::getEnv('SS_DATABASE_SCHEMA');
        if ($dbSchema) {
            $databaseConfig["schema"] = $dbSchema;
        }

        // For SQlite3 memory databases (mainly for testing purposes)
        $dbMemory = Environment::getEnv('SS_DATABASE_MEMORY');
        if ($dbMemory) {
            $databaseConfig["memory"] = $dbMemory;
        }

        // Allow database adapters to handle their own configuration
        DatabaseAdapterRegistry::autoconfigure($databaseConfig);
        return $databaseConfig;
    }
693728
public function getAdapter()
    {
        if (is_null($this->adapter) || ! $this->adapter instanceof AdapterInterface) {
            $class = '\\Wslim\\Db\Adapter\\' . $this->options['adapter'] . 'Adapter';
            if (!class_exists($class)) {
                throw new DbException('database adapter is not exists:' . $class);
            }
            
            $this->adapter  =   new $class($this->options);
        }
        
        return $this->adapter;
    }
8859
public function getDefaultEnvironment()
    {
        // if the user has configured a default database then use it,
        // providing it actually exists!
        if (isset($this->values['environments']['default_database'])) {
            if ($this->getEnvironment($this->values['environments']['default_database'])) {
                return $this->values['environments']['default_database'];
            }

            throw new \RuntimeException(sprintf(
                'The environment configuration for \'%s\' is missing',
                $this->values['environments']['default_database']
            ));
        }

        // else default to the first available one
        if (is_array($this->getEnvironments()) && count($this->getEnvironments()) > 0) {
            $names = array_keys($this->getEnvironments());

            return $names[0];
        }

        throw new \RuntimeException('Could not find a default environment');
    }
207224
public static function instance()
    {
        if (empty(self::$databaseInstance)) {
            self::$databaseInstance = new static(self::$config);
        }
        return self::$databaseInstance;
    }
1329010
public function getSourceDatabase()
    {
        if (! $this->_sourceDb) {

            if ($dbConfig['dbname'] = $this->_sourceData['gso_ls_database']) {

                // Default config values from gemsDb
                $gemsConfig = $this->_gemsDb->getConfig();
                $gemsName   = $gemsConfig['dbname'];

                if (($dbConfig['dbname'] != $gemsName) &&
                    ($adapter = $this->_sourceData['gso_ls_adapter'])) {

                    //If upgrade has run and we have a 'charset' use it
                    if (array_key_exists('gso_ls_charset', $this->_sourceData)) {
                        $dbConfig['charset'] = $this->_sourceData['gso_ls_charset']
                                ? $this->_sourceData['gso_ls_charset']
                                : $gemsConfig['charset'];
                    }
                    $dbConfig['host']     = $this->_sourceData['gso_ls_dbhost']
                            ? $this->_sourceData['gso_ls_dbhost']
                            : $gemsConfig['host'];
                    if (isset($this->_sourceData['gso_ls_dbport'])) {
                        $dbConfig['port'] = $this->_sourceData['gso_ls_dbport'];
                    } elseif (isset($gemsConfig['port'])) {
                        $dbConfig['port'] = $gemsConfig['port'];
                    }
                    $dbConfig['username'] = $this->_sourceData['gso_ls_username']
                            ? $this->_sourceData['gso_ls_username']
                            : $gemsConfig['username'];
                    $dbConfig['password'] = $this->_sourceData['gso_ls_password']
                            ? $this->project->decrypt($this->_sourceData['gso_ls_password'])
                            : $gemsConfig['password'];

                    $this->_sourceDb = \Zend_Db::factory($adapter, $dbConfig);
                }
            }

            // In all other cases use $_gemsDb
            if (! $this->_sourceDb) {
                $this->_sourceDb = $this->_gemsDb;
            }
        }

        return $this->_sourceDb;
    }
1095688
public static function getDb() {
        // Get the image manager object
        $oImageManager = Yii::$app->get('imagemanager', false);

        if($oImageManager === null) {
            // The image manager object has not been set
            // The normal DB object will be returned, error will be thrown if not found
            return Yii::$app->get('db');
        }

        // The image manager component has been loaded, the DB component that has been entered will be loaded
        // By default this is the Yii::$app->db connection, the user can specify any other connection if needed
        return Yii::$app->get($oImageManager->databaseComponent);
    }
1319514
public function getDatabase()
    {
        if (self::$database === null) {
            self::$database = self::mongo(self::getConfig()->Database);
        }

        return self::$database;
    }
100503
protected function getDb()
    {
        return \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
    }
74870
public static function db()
    {
        self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return self::$conn;
    }
400028
public function getDefaultDatabase()
    {
        if (!isset($this->_config['database'])) {
            throw new Exception(sprintf('You have not configured a default database for Datasource %s yet.', $this->_config['name']));
        }
        $db = $this->_config['database'];
        return $this->connect()->database($db);
    }
1137360
protected function getDatabaseName()
    {
        // Check globals
        global $database;

        if (!empty($database)) {
            return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
        }

        global $databaseConfig;

        if (!empty($databaseConfig['database'])) {
            return $databaseConfig['database']; // Note: Already includes prefix
        }

        // Check environment
        $database = Environment::getEnv('SS_DATABASE_NAME');

        if ($database) {
            return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
        }

        // Auto-detect name
        $chooseName = Environment::getEnv('SS_DATABASE_CHOOSE_NAME');

        if ($chooseName) {
            // Find directory to build name from
            $loopCount = (int)$chooseName;
            $databaseDir = $this->basePath;
            for ($i = 0; $i < $loopCount-1; $i++) {
                $databaseDir = dirname($databaseDir);
            }

            // Build name
            $database = str_replace('.', '', basename($databaseDir));
            $prefix = $this->getDatabasePrefix();

            if ($prefix) {
                $prefix = 'SS_';
            } else {
                // If no prefix, hard-code prefix into database global
                $prefix = '';
                $database = 'SS_' . $database;
            }

            return $prefix . $database;
        }

        // no DB name (may be optional for some connectors)
        return null;
    }
74504
public function getDatabase($name = null)
    {
        if (empty($name)) {
            $name = $this->getCurrentDatabaseName();
        }

        if (!isset($this->databasePool[$name])) {
            // init db
            $database = new Database($this, $name);
            if (isset($this->mapping[$name])) {
                $database->map($this->mapping[$name]);
            }

            // configure db
            $this->databasePool[$name] = $database;
        }
        
        return $this->databasePool[$name];
    }
638880
public function db($db = null)
    {
        if ($db === null)
        {
            return $this->_db;
        }
        $this->_db = $db;

        return $this;
    }
1331912
private function _getDefaultDB()
    {
        // For ReadDatabase checking Master first
        if ($this->_db) {
            return $this->_db;
        }
        
        if (!isset($this->db)) {
            get_instance()->load->database();
        }
        // No need to set as reference because $this->db is refered to &DB already.
        return get_instance()->db;
    }
866005
public static function getDatabase()
    {
        $attribute = 'database';

        if (!static::hasClassAttribute($attribute)) {
            $database = Database::getDefault();

            if (!$database) {
                $error = static::error('connection', 'database not found', 'required-for', 6);
                switch (static::getClassConfig('error-mode')) {
                    case 'silent': break;
                    case 'exception': throw new Exception($error);
                    default: trigger_error($error, E_USER_ERROR);
                }
            }

            static::setClassAttribute($attribute, $database);
        }

        return static::getClassAttribute($attribute);
    }
799854
public function database()
    {
        $databaseManager = new DatabaseManager;
        $response = $databaseManager->migrateAndSeed();

        return redirect()->route('LaravelUpdater::final')
                         ->with(['message' => $response]);
    }