Function setDatabase

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 2018-12-02 20:42

@param array  $database
@param string $name

@return $this
772104
public function setDatabase($database = [], $name = 'default')
    {
        $this->database = $database;
        $this->dbName   = $name;

        return $this;
    }
709870
public function setDBO(&$db)
	{
		// Make sure the new database object is a Database.
		if (!($db instanceof \Hubzero\Database\Driver))
		{
			return false;
		}

		$this->_db = &$db;

		return true;
	}
1092999
public function select($database)
	{
		$this->connect();

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

		$this->execute();

		return $this;
	}
190802
public function addDatabase($db)
    {
        if ($db instanceof Database) {
            $db->setAppData($this);
            if ($db->getPlatform() === null) {
                if ($config = $this->getGeneratorConfig()) {
                    $pf = $config->getConfiguredPlatform(null, $db->getName());
                    $db->setPlatform($pf ? $pf : $this->platform);
                } else {
                    $db->setPlatform($this->platform);
                }
            }
            $this->dbList[] = $db;

            return $db;
        } else {
            // XML attributes array / hash
            $d = new Database();
            $d->setAppData($this);
            $d->loadFromXML($db);

            return $this->addDatabase($d); // calls self w/ different param type
        }
    }
128632
public function setDatabase ($name, $user, $pass, $host = 'localhost', $port = 3306)
    {
        $this->database['name'] = $name;
        $this->database['user'] = $user;
        $this->database['pass'] = $pass;
        $this->database['host'] = $host;
        $this->database['port'] = $port;

        return $this;
    }
65456
public function set($name, $value = null)
    {
        if (is_array($name)) {
            $insert = [];
            $delete = [];

            foreach ($name as $key => $val) {
                $val = $this->_merge($key, $val);
                $insert[] = [$key, $val];
                $delete[] = $key;

                $this->_data[$key] = $val;
            }
            if (count($insert) > 0) {
                $this->_db->createCommand()->delete($this->tableName, ['IN', 'name', $delete])->execute();
                $this->_db->createCommand()->batchInsert($this->tableName, ['name', 'value'], $insert)->execute();
            }
        } else {
            $value = $this->_merge($name, $value);

            if (array_key_exists($name, $this->getData()) === false) {
                $this->_db->createCommand()->insert($this->tableName, ['name' => $name, 'value' => $value])->execute();
            } else {
                $this->_db->createCommand()->update($this->tableName, ['value' => $value], 'name = :name', [':name' => $name])->execute();
            }
            $this->_data[$name] = $value;
        }

        $this->_setCache();
    }
1033316
public function setDatabaseInfo($data)
    {
        $data['host'] = $data['host'].':'.$data['port'];

        unset($data['port']);

        $keys = array_map(function($key) {
            return 'database_'.$key;
        }, array_keys($data));

        $data = array_combine($keys, array_values($data));

        $this->set($data);
    }
1133582
protected function createDatabase(string $name): void
    {
        $this->files->put($this->moduleName().'/'.$name.'/Database/Factories/UserFactory.php', $this->files->get(__DIR__.'/stubs/factory.stub'));
        $this->files->put($this->moduleName().'/'.$name.'/Database/Migrations/2014_10_12_000000_test_table.php', $this->files->get(__DIR__.'/stubs/migration.stub'));
        $this->files->put($this->moduleName().'/'.$name.'/Database/Seeds/DatabaseSeeder.php', $this->files->get(__DIR__.'/stubs/seed.stub'));
    }
59340
static public function db($name=null)
	{
	    $id = 'db' . ($name ? '.' . $name : '');
	    if (!static::has($id)) {
	        static::setShared($id, function () use($name) {
	            Config::load('database');
	            $config = (array)Config::get('database');
	            if ($config) {
	                $config = ArrayHelper::getItemArray($config, $name);
	            }
	            
	            return new Db($config);
	        });
	    }
	    
	    return static::get($id);
	}
1055660
public function addDatabase($database)
    {
        if ($database instanceof Database) {
            $platform = null;
            $database->setParentSchema($this);
            if (null === $database->getPlatform()) {
                if ($config = $this->getGeneratorConfig()) {
                    $platform = $config->getConfiguredPlatform(null, $database->getName());
                }

                $database->setPlatform($platform ? $platform : $this->platform);
            }
            $this->databases[] = $database;

            return $database;
        }

        // XML attributes array / hash
        $db = new Database();
        $db->setParentSchema($this);
        $db->loadMapping($database);

        return $this->addDatabase($db);
    }
871770
public function setDatabase($database)
    {
        if (! $database instanceof MongoDB) {
            $database = $this->connection->getConnection()->{$database};
        }

        $this->database = $database;

        return $this;
    }
1228364
protected function makeDatabase(DatabasePartial $database): Database
    {
        return new Database(
            $database->getName(),
            $database->getPrefix(),
            $this->driver($database->getDriver()),
            $database->getReadDriver() ? $this->driver($database->getReadDriver()) : null
        );
    }
944547
public function db_select($database = '')
	{
		if ($database === '')
		{
			$database = $this->database;
		}

		if (mysql_select_db($database, $this->conn_id))
		{
			$this->database = $database;
			return TRUE;
		}

		return FALSE;
	}
226937
protected function setDatabase($name) {
        if (isset($name) && !is_string($name)) throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name));
        if (!strlen($name))
            $name = null;

        $this->database = $name;
        return $this;
    }
284665
public function &setDatabaseName($database_name, $select_database = true)
    {
        if (empty($select_database) || $this->link->select_db($database_name)) {
            $this->database_name = $database_name;
        } else {
            throw new ConnectionException("Failed to select database '$database_name'");
        }

        return $this;
    }
1123814
public function setDbo(&$db)
	{
		if (!($db instanceof \Hubzero\Database\Driver))
		{
			return false;
		}

		$this->_db = $db;
		$this->_tbl->setDBO($this->_db);

		return true;
	}
556389
protected function _select_db($database)
	{
		if ( ! mysql_select_db($database, $this->_connection))
		{
			// Unable to select database
			throw new \Database_Exception(mysql_error($this->_connection), mysql_errno($this->_connection));
		}

		static::$_current_databases[$this->_connection_id] = $database;
	}