Opens a connection to the MySQL Server and selects the specified database

@access public
@param string $dbname
765870
function Connect()
	{
		$this->handler->Log(DBH_LOG_INFO, "Opening Connection...");
		if ($this->dbopen)
		{
			$this->handler->Log(DBH_LOG_WARNING, "Connection Already Open");
		}
		else
		{
			$this->adapter = new DataAdapter($this->csetting);
			
			try {
				$this->adapter->Open();
			}
			catch (Exception $ex) {
				$this->handler->Crash(DatabaseException::$CONNECTION_ERROR,$ex->getMessage());
			}

			$this->handler->Log(DBH_LOG_INFO, "Connection Open");
			$this->dbopen = true;
		}
	}
1070366
public function use_database($db_name)
    {
        if (!$this->connection) {
            $this->last_error_id = "db_server_conn_error";
            return false;
        }
        
        $this->db_name = $db_name;
        
        $db_name = $this->escape($db_name);
        
        if (!$this->execute_query("USE " . $db_name)) {
            $this->last_error = $this->sys_get_errors();
            $this->last_error_id = "db_not_exists_error";
            return false;
        }
        
        return true;
    }
1087722
private function connect()
    {
        // Connecting with PDO.
        try {
            switch ($this->dbType) {
                case 'sqlite':
                    $this->dbHandler = @new PDO("sqlite:".$this->dbName, null, null, $this->pdoSettings);
                    break;
                case 'mysql':
                case 'pgsql':
                case 'dblib':
                    $this->dbHandler = @new PDO(
                        $this->dsn,
                        $this->user,
                        $this->pass,
                        $this->pdoSettings
                    );
                    // Execute init commands once connected
                    foreach ($this->dumpSettings['init_commands'] as $stmt) {
                        $this->dbHandler->exec($stmt);
                    }
                    // Store server version
                    $this->version = $this->dbHandler->getAttribute(PDO::ATTR_SERVER_VERSION);
                    break;
                default:
                    throw new Exception("Unsupported database type (".$this->dbType.")");
            }
        } catch (PDOException $e) {
            throw new Exception(
                "Connection to ".$this->dbType." failed with message: ".
                $e->getMessage()
            );
        }

        if (is_null($this->dbHandler)) {
            throw new Exception("Connection to ".$this->dbType."failed");
        }

        $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
        $this->typeAdapter = TypeAdapterFactory::create($this->dbType, $this->dbHandler, $this->dumpSettings);
    }
79568
protected static function initSessionStorage(string $dbName) : void
    {
        if (!isset($_SESSION['databases']) || !\is_array($_SESSION['databases'])) {
            $_SESSION['databases'] = [];
        }

        if (!isset($_SESSION['databases'][$dbName]) || !\is_array($_SESSION['databases'][$dbName])) {
            $_SESSION['databases'][$dbName] = ['tables' => []];
        }
    }
96145
public function create_database($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) {
        global $CFG;

        $this->dbhost = $dbhost;
        $this->dbuser = $dbuser;
        $this->dbpass = $dbpass;
        $this->dbname = $dbname;
        $filepath = $this->get_dbfilepath();
        $dirpath = dirname($filepath);
        @mkdir($dirpath, $CFG->directorypermissions, true);
        return touch($filepath);
    }
1247366
public function select_database($database)
    {
        //        try{

        if ($this->pdo) {
            if ($this->pdo->exec('USE ' . $database) !== FALSE) {
                return true;
            }
        }
        //        }catch(\Exception $ex)
        //        {
        //            new Exception($this->getLastError());
        //        }
        return false;
    }
1026087
public function use_database($db_name)
    {
        if (!$this->mysqli) {
            $this->last_error_id = "db_server_conn_error";
            return false;
        }
        
        $this->db_name = $db_name;
        
        if (!@$this->mysqli->select_db($this->db_name)) {
            $this->last_error = $this->mysqli->error;
            $this->last_error_id = "db_not_exists_error";
            trigger_error($this->last_error, E_USER_ERROR);
            return false;
        }
        
        return true;
    }
1207383
function open()
    {
        if (!$this->_opened) {
            /* Use the DSN and options to create a database connection. */
            $this->_db = &DB::connect($this->_dsn, $this->_options);
            if (DB::isError($this->_db)) {
                return false;
            }

            /* Create a prepared statement for repeated use in log(). */
            if (!$this->_prepareStatement()) {
                return false;
            }

            /* We now consider out connection open. */
            $this->_opened = true;
        }

        return $this->_opened;
    }
893686
public function connect($server,$user,$password,$database){
		if(empty($this->database_info['server']) || $this->database_info['server']==''){
			$this->database_info['server'] = $server;
		}
		if(empty($this->database_info['user']) || $this->database_info['user']==''){
			$this->database_info['user'] = $user;
		}
		if(empty($this->database_info['pass']) || $this->database_info['pass']==''){
			$this->database_info['pass'] = $password;
		}
		if(empty($this->database_info['database']) || $this->database_info['database']==''){
			$this->database_info['database'] = $database;
		}

		mysql_connect(
		$this->database_info['server'],
		$this->database_info['user'],
		$this->database_info['pass']
		);
		@mysql_select_db($this->database_info['database']) or die("Unable to connect to ".$this->database_info['database']." database.");
	}
1360678
private function connectToDb()
    {
        if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) {
            $this->handleError();
        } else if (!@mysql_select_db($this->dbName, $this->dbConn)) {
            $this->handleError();
        }
    }
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;
	}
117414
public function makeSelect(string $connectionName = ''): SelectQueryBuilder
    {
        $connection = $this->provideConnection($connectionName);
        $statementBuilder = new SelectStatementBuilder;
        return new SelectQueryBuilder($connection, $statementBuilder);
    }
925427
public function createTbl($dbname, $sql)
    {
        if (isset($dbname) && !empty(trim($dbname)) && isset($sql) && !empty(trim($sql))) {
            $this->db->exec("USE `{$dbname}` ");

            $this->db->exec($sql);

            return true;
        } else {
            return false;
        }
    }
185555
public function setDbCollection(string $dbName, string $collectionName): \MongoCollection
    {
        return $this->mongoClient->selectDB($dbName)->selectCollection($collectionName);
    }
1029246
public function select()
    {
        $this->db->disconnect();

        $this->db->setDatabaseName($this->getName());

        return $this;
    }
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;
    }
1278083
public static function connection(?string $connectionName=null): Connection {
        if ($connectionName == null) {
            $connectionName = get_property("database.default");
            if ($connectionName == null) {
                throw new RuntimeException("No default database was configured !!");
            }
        }
        if (!isset(self::$connections[$connectionName])) {
            $connectionsConfig = get_property("database.connections", []);
            if (!isset($connectionsConfig[$connectionName])) {
                throw new RuntimeException("Database connection with name \"$connectionName\" doesnt exist !!");
            }

            $connectionConfig = $connectionsConfig[$connectionName];
            $connectionDriver = $connectionConfig["driver"];
            $connectionQueryBuilder = null;
            switch ($connectionDriver) {
                case "pgsql":
                    $connectionQueryBuilder = new PostgresQueryBuilder();
                    break;
                default:
                    $builderClasses = get_property("database.builders", []);
                    if (isset($builderClasses[$connectionDriver])) {
                        $connectionQueryBuilder = $builderClasses[$connectionDriver];
                    }
                    else {
                        throw new RuntimeException("Database driver \"$connectionDriver\" not supported !!. Consider adding a builder class for the driver.");
                    }
                    break;
            }
            $connectionDsn = $connectionDriver;
            $connectionDsn .= ":host=" . $connectionConfig["host"];
            $connectionDsn .= ";port=" . $connectionConfig["port"];
            $connectionDsn .= ";dbname=" . $connectionConfig["database"];
            $connectionPdo = new PDO($connectionDsn, $connectionConfig["username"], $connectionConfig["password"]);
            if (!empty($connectionConfig["emulate_prepared_statements"])) {
                $connectionPdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
            }
            self::$connections[$connectionName] = new Connection($connectionPdo, $connectionQueryBuilder, $connectionConfig);
        }
        return self::$connections[$connectionName];
    }