source/Setup/Database.php
public function openDatabase($aParams)
    {
        $aParams = (is_array($aParams) && count($aParams)) ? $aParams : $this->getInstance("Session")->getSessionParam('aDB');
        if ($this->_oConn === null) {
            // ok open DB
            try {
                $dsn = sprintf('mysql:host=%s;port=%s', $aParams['dbHost'], $aParams['dbPort']);
                $this->_oConn = new PDO(
                    $dsn,
                    $aParams['dbUser'],
                    $aParams['dbPwd'],
                    [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']
                );
                $this->_oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $this->_oConn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
            } catch (PDOException $e) {
                /** @var Setup $oSetup */
                $oSetup = $this->getInstance("Setup");
                $oSetup->setNextStep($oSetup->getStep('STEP_DB_INFO'));
                throw new Exception($this->getInstance("Language")->getText('ERROR_DB_CONNECT') . " - " . $e->getMessage(), Database::ERROR_DB_CONNECT, $e);
            }

            // testing version
            $oSysReq = getSystemReqCheck();
            if (0 === $oSysReq->checkMysqlVersion($this->getDatabaseVersion())) {
                throw new Exception($this->getInstance("Language")->getText('ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS'), Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS);
            }

            $databaseConnectProblem = null;
            try {
                $this->_oConn->exec("USE `{$aParams['dbName']}`");
            } catch (Exception $e) {
                $databaseConnectException = new Exception($this->getInstance("Language")->getText('ERROR_COULD_NOT_CREATE_DB') . " - " . $e->getMessage(), Database::ERROR_COULD_NOT_CREATE_DB, $e);
            }

            if ((1 === $oSysReq->checkMysqlVersion($this->getDatabaseVersion())) && !$this->userDecidedIgnoreDBWarning()) {
                throw new Exception($this->getInstance("Language")->getText('ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS'), Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS);
            }

            if (is_a($databaseConnectException, 'Exception')) {
                throw $databaseConnectException;
            }
        } else {
            // Make sure the database is connected
            $this->connectDb($aParams['dbName']);
        }

        return $this->_oConn;
    }
public function openDatabase($aParams)
    {
        $aParams = (is_array($aParams) && count($aParams)) ? $aParams : $this->getInstance("Session")->getSessionParam('aDB');
        if ($this->_oConn === null) {
            // ok open DB
            try {
                $dsn = sprintf('mysql:host=%s;port=%s', $aParams['dbHost'], $aParams['dbPort']);
                $this->_oConn = new PDO(
                    $dsn,
                    $aParams['dbUser'],
                    $aParams['dbPwd'],
                    [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']
                );
                $this->_oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $this->_oConn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
            } catch (PDOException $e) {
                /** @var Setup $oSetup */
                $oSetup = $this->getInstance("Setup");
                $oSetup->setNextStep($oSetup->getStep('STEP_DB_INFO'));
                throw new Exception($this->getInstance("Language")->getText('ERROR_DB_CONNECT') . " - " . $e->getMessage(), Database::ERROR_DB_CONNECT, $e);
            }

            // testing version
            $oSysReq = getSystemReqCheck();
            if (0 === $oSysReq->checkMysqlVersion($this->getDatabaseVersion())) {
                throw new Exception($this->getInstance("Language")->getText('ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS'), Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS);
            }

            $databaseConnectProblem = null;
            try {
                $this->_oConn->exec("USE `{$aParams['dbName']}`");
            } catch (Exception $e) {
                $databaseConnectException = new Exception($this->getInstance("Language")->getText('ERROR_COULD_NOT_CREATE_DB') . " - " . $e->getMessage(), Database::ERROR_COULD_NOT_CREATE_DB, $e);
            }

            if ((1 === $oSysReq->checkMysqlVersion($this->getDatabaseVersion())) && !$this->userDecidedIgnoreDBWarning()) {
                throw new Exception($this->getInstance("Language")->getText('ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS'), Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS);
            }

            if (is_a($databaseConnectException, 'Exception')) {
                throw $databaseConnectException;
            }
        } else {
            // Make sure the database is connected
            $this->connectDb($aParams['dbName']);
        }

        return $this->_oConn;
    }
public function openDatabase ( $ aParams ) { $ aParams = ( is_array ( $ aParams ) && count ( $ aParams ) ) ? $ aParams : $ this -> getInstance ( "Session" ) -> getSessionParam ( 'aDB' ) ; if ( $ this -> _oConn === null ) { // ok open DB try { $ dsn = sprintf ( 'mysql:host=%s;port=%s' , $ aParams [ 'dbHost' ] , $ aParams [ 'dbPort' ] ) ; $ this -> _oConn = new PDO ( $ dsn , $ aParams [ 'dbUser' ] , $ aParams [ 'dbPwd' ] , [ PDO :: MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ] ) ; $ this -> _oConn -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; $ this -> _oConn -> setAttribute ( PDO :: ATTR_DEFAULT_FETCH_MODE , PDO :: FETCH_ASSOC ) ; } catch ( PDOException $ e ) { /** @var Setup $oSetup */ $ oSetup = $ this -> getInstance ( "Setup" ) ; $ oSetup -> setNextStep ( $ oSetup -> getStep ( 'STEP_DB_INFO' ) ) ; throw new Exception ( $ this -> getInstance ( "Language" ) -> getText ( 'ERROR_DB_CONNECT' ) . " - " . $ e -> getMessage ( ) , Database :: ERROR_DB_CONNECT , $ e ) ; } // testing version $ oSysReq = getSystemReqCheck ( ) ; if ( 0 === $ oSysReq -> checkMysqlVersion ( $ this -> getDatabaseVersion ( ) ) ) { throw new Exception ( $ this -> getInstance ( "Language" ) -> getText ( 'ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS' ) , Database :: ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS ) ; } $ databaseConnectProblem = null ; try { $ this -> _oConn -> exec ( "USE `{$aParams['dbName']}`" ) ; } catch ( Exception $ e ) { $ databaseConnectException = new Exception ( $ this -> getInstance ( "Language" ) -> getText ( 'ERROR_COULD_NOT_CREATE_DB' ) . " - " . $ e -> getMessage ( ) , Database :: ERROR_COULD_NOT_CREATE_DB , $ e ) ; } if ( ( 1 === $ oSysReq -> checkMysqlVersion ( $ this -> getDatabaseVersion ( ) ) ) && ! $ this -> userDecidedIgnoreDBWarning ( ) ) { throw new Exception ( $ this -> getInstance ( "Language" ) -> getText ( 'ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS' ) , Database :: ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS ) ; } if ( is_a ( $ databaseConnectException , 'Exception' ) ) { throw $ databaseConnectException ; } } else { // Make sure the database is connected $ this -> connectDb ( $ aParams [ 'dbName' ] ) ; } return $ this -> _oConn ; }
Opens database connection and returns connection resource object

@param array $aParams database connection parameters array

@throws Exception exception is thrown if connection failed or was unable to select database

@return object
Opens database connection and returns connection resource object