Wrapper method for MongoClient::selectDatabase().

This method will dispatch preSelectDatabase and postSelectDatabase
events.

@see http://php.net/manual/en/mongoclient.selectdatabase.php
@param string $name
@return Database
438365
public function selectDatabase($name)
    {
        if ($this->eventManager->hasListeners(Events::preSelectDatabase)) {
            $this->eventManager->dispatchEvent(Events::preSelectDatabase, new EventArgs($this, $name));
        }

        $this->initialize();
        $database = $this->doSelectDatabase($name);

        if ($this->eventManager->hasListeners(Events::postSelectDatabase)) {
            $this->eventManager->dispatchEvent(Events::postSelectDatabase, new EventArgs($this, $database));
        }

        return $database;
    }
816172
protected function subselect_query($name)
    {
        if (isset($this->subselect_query[$name]))
        {
            $sql = $this->subselect_query[$name];
        }
        else
        {
            $sql = preg_replace_callback('/\{(.+)\}/Uu', array($this, 'subselect_callback'), $this->subselect[$name]);
            $this->subselect_query[$name] = $sql;
        }
        return "({$sql}) AS `{$name}`";
    }
185555
public function setDbCollection(string $dbName, string $collectionName): \MongoCollection
    {
        return $this->mongoClient->selectDB($dbName)->selectCollection($collectionName);
    }
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);
    }
1092999
public function select($database)
	{
		$this->connect();

		$this->setQuery('USE ' . $this->quoteName($database));

		$this->execute();

		return $this;
	}
974459
public static function database($name = 'default')
    {
        if (!isset(static::$databases[$name])) {

            $cache = Config::get('cache');

            if (!isset($cache['storage']) || $cache['storage'] != 'redis') {
                throw new \RuntimeException("Redis database [$name] is not defined.");
            }

            static::$databases[$name] = new static(
                new Adapter\Socket($cache['server']['host'], $cache['server']['port']),
                $cache['server']['database']
            );
        }

        return static::$databases[$name];
    }
446521
public function getDatabaseInfo($name = null)
    {
        $response = $this->httpClient->request('GET', '/'.($name ? urlencode($name) : $this->databaseName));

        if ($response->status != 200) {
            throw HTTPException::fromResponse('/'.urlencode($name), $response);
        }

        return $response->body;
    }
1254776
public function selectDB($name)
    {
        $this->dbname = $name;

        if ($this->state !== 1) {
            return $this->query('USE `' . $name . '`');
        }

        return true;
    }
27087
public function database(string $database = null): MongoDatabase
    {
        if (empty($database)) {
            $database = $this->config->defaultDatabase();
        }

        //Spiral support ability to link multiple virtual databases together using aliases
        $database = $this->config->resolveAlias($database);

        if (isset($this->databases[$database])) {
            return $this->databases[$database];
        }

        if (!$this->config->hasDatabase($database)) {
            throw new ODMException(
                "Unable to initiate MongoDatabase, no presets for '{$database}' found"
            );
        }

        $options = $this->config->databaseOptions($database);

        //Initiating database instance
        return $this->createDatabase(
            $database,
            $options['server'],
            $options['database'],
            $options['driverOptions'] ?? [],
            $options['options'] ?? []
        );
    }
1109296
public function getDatabase($name = null, $doFinalInit = true)
    {
        // this is temporary until we'll have a clean solution
        // for packaging datamodels/requiring schemas
        if ($doFinalInit) {
            $this->doFinalInitialization();
        }

        if ($name === null) {
            return $this->dbList[0];
        }

        for ($i = 0, $size = count($this->dbList); $i < $size; $i++) {
            $db = $this->dbList[$i];
            if ($db->getName() === $name) {
                return $db;
            }
        }

        return null;
    }
56787
public function createDatabase($name)
    {
        $response = $this->httpClient->request('PUT', '/'.urlencode($name));

        if ($response->status != 201) {
            throw HTTPException::fromResponse('/'.urlencode($name), $response);
        }
    }
730210
public function createDatabase($name)
    {
        if (preg_match('@[^a-z0-9\_\$\(\)+\-]@', $name)) {
            throw new InvalidDatabasenameException(sprintf(
                'The database name %s is invalid. The database name must match the following pattern (a-z0-9_$()+-)',
                $name
            ));
        }

        if ($this->eventManager->hasListeners(Events::PRE_CREATE_DATABASE)) {
            // @codeCoverageIgnoreStart
            $this->eventManager->dispatchEvent(Events::PRE_CREATE_DATABASE, new EventArgs($this, $name));
            // @codeCoverageIgnoreEnd
        }

        $response = $this->client->request('PUT', sprintf('/%s', $name));

        if (412 === $response->getStatusCode()) {
            throw new Exception(sprintf('The database "%s" already exist', $name));
        }

        $json = (string) $response->getBody();
        $value = JSONEncoder::decode($json);

        if (isset($value['error'])) {
            throw new Exception(sprintf('[%s] Failed to create database "%s". (%s)', $value['error'], $name, $value['reason']));
        }

        $database = $this->wrapDatabase($name);

        if ($this->eventManager->hasListeners(Events::POST_CREATE_DATABASE)) {
            // @codeCoverageIgnoreStart
            $this->eventManager->dispatchEvent(Events::POST_CREATE_DATABASE, new EventArgs($database));
            // @codeCoverageIgnoreEnd
        }

        return $database;
    }
242795
public function dropDatabase($name)
    {
        if ($this->eventManager->hasListeners(Events::PRE_DROP_DATABASE)) {
            // @codeCoverageIgnoreStart
            $this->eventManager->dispatchEvent(Events::PRE_DROP_DATABASE, new EventArgs($this, $name));
            // @codeCoverageIgnoreEnd
        }

        $response = $this->client->request('DELETE', sprintf('/%s/', urlencode($name)));

        if (404 === $response->getStatusCode()) {
            throw new Exception(sprintf('The database "%s" does not exist', $name));
        }

        $json = (string) $response->getBody();
        $status = JSONEncoder::decode($json);

        if ($this->eventManager->hasListeners(Events::POST_DROP_DATABASE)) {
            // @codeCoverageIgnoreStart
            $this->eventManager->dispatchEvent(Events::POST_DROP_DATABASE, new EventArgs($this, $name));
            // @codeCoverageIgnoreEnd
        }

        return isset($status['ok']) && $status['ok'] === true;
    }
1079738
public function select()
    {
        $query     = 'SELECT ' . $this->getQueryFields() . ' FROM ' . $this->getTable() . ' ' . $this->getQueryWhere() . ' ' . $this->getQueryOrderBy() . ' ' . $this->getQueryLimit();
        $statement = $this->db->prepare($query);
        $statement->execute($this->binds);

        $this->clear();

        $collection = array();

        while (false !== ($row = $statement->fetchObject())) {
            $collection[] = $this->newDataInstance($row, true);
        }

        return $collection;
    }
977999
private function getCollection($type) {
        if ($this->collections[$type] === null) {
            try {
                $this->collections[$type] = $this->getMongoClient()->selectCollection(
                    $this->params['databaseName'],
                    $type
                );
            } catch (MongoException $e) {
                throw new DatabaseException('Could not select collection', 500, $e);
            }
        }

        return $this->collections[$type];
    }
960942
public function dropDatabase($database)
    {
        if ($this->eventManager->hasListeners(Events::preDropDatabase)) {
            $this->eventManager->dispatchEvent(Events::preDropDatabase, new EventArgs($this, $database));
        }

        $this->initialize();
        $result = $this->mongoClient->dropDB($database);

        if ($this->eventManager->hasListeners(Events::postDropDatabase)) {
            $this->eventManager->dispatchEvent(Events::postDropDatabase, new EventArgs($this, $result));
        }

        return $result;
    }
1090756
public function selectDatabase($database)
    {
        $mysqli = $this->_mysqli();

        if(!$mysqli->select_db($database))
            throw new Exception($mysqli->error, $mysqli->errno);

        $this->_selectedDatabase = $database;

        return $this;
    }