source/Setup/Controller.php
public function dbConnect()
    {
        $setup = $this->getSetupInstance();
        $session = $this->getSessionInstance();
        $language = $this->getLanguageInstance();

        $view = $this->getView();
        $view->setTitle('STEP_3_1_TITLE');

        $databaseConfigValues = $this->getUtilitiesInstance()->getRequestVar("aDB", "post");
        $session->setSessionParam('aDB', $databaseConfigValues);

        // check if important parameters are set
        if (!$databaseConfigValues['dbHost'] || !$databaseConfigValues['dbName']) {
            $setup->setNextStep($setup->getStep('STEP_DB_INFO'));
            $view->setMessage($language->getText('ERROR_FILL_ALL_FIELDS'));

            throw new SetupControllerExitException();
        }

        try {
            // ok check DB Connection
            $database = $this->getDatabaseInstance();
            $database->openDatabase($databaseConfigValues);
        } catch (Exception $exception) {
            if ($exception->getCode() === Database::ERROR_DB_CONNECT) {
                $setup->setNextStep($setup->getStep('STEP_DB_INFO'));
                $view->setMessage($language->getText('ERROR_DB_CONNECT') . " - " . $exception->getMessage());

                throw new SetupControllerExitException();
            } elseif ($exception->getCode() === Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS) {
                $setup->setNextStep($setup->getStep('STEP_DB_INFO'));
                $view->setMessage($exception->getMessage());

                throw new SetupControllerExitException();
            } elseif (($exception->getCode() === Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS)) {
                $setup->setNextStep(null);
                $this->formMessageIfMySqyVersionIsNotRecommended($view, $language);
                $databaseExists = false;
                // check if DB is already UP and running
                if (!$this->databaseCanBeOverwritten($database)) {
                    $this->formMessageIfDBCanBeOverwritten($databaseConfigValues['dbName'], $view, $language);
                    $databaseExists = true;
                }
                $this->formMessageIgnoreDbVersionNotRecommended($view, $language, $session->getSid(), $setup->getStep('STEP_DIRS_INFO'), $databaseExists);

                throw new SetupControllerExitException();
            } else {
                $this->ensureDatabasePresent($database, $databaseConfigValues['dbName']);
            }
        }

        $view->setViewParam("aDB", $databaseConfigValues);

        // check if DB is already UP and running
        if (!$this->databaseCanBeOverwritten($database)) {
            $this->formMessageIfDBCanBeOverwritten($databaseConfigValues['dbName'], $view, $language);
            $this->formMessageInstallAnyway($view, $language, $session->getSid(), $setup->getStep('STEP_DIRS_INFO'));

            throw new SetupControllerExitException();
        }

        $setup->setNextStep($setup->getStep('STEP_DIRS_INFO'));

        $this->view->setTemplateFileName("dbconnect.php");
    }
public function dbConnect()
    {
        $setup = $this->getSetupInstance();
        $session = $this->getSessionInstance();
        $language = $this->getLanguageInstance();

        $view = $this->getView();
        $view->setTitle('STEP_3_1_TITLE');

        $databaseConfigValues = $this->getUtilitiesInstance()->getRequestVar("aDB", "post");
        $session->setSessionParam('aDB', $databaseConfigValues);

        // check if important parameters are set
        if (!$databaseConfigValues['dbHost'] || !$databaseConfigValues['dbName']) {
            $setup->setNextStep($setup->getStep('STEP_DB_INFO'));
            $view->setMessage($language->getText('ERROR_FILL_ALL_FIELDS'));

            throw new SetupControllerExitException();
        }

        try {
            // ok check DB Connection
            $database = $this->getDatabaseInstance();
            $database->openDatabase($databaseConfigValues);
        } catch (Exception $exception) {
            if ($exception->getCode() === Database::ERROR_DB_CONNECT) {
                $setup->setNextStep($setup->getStep('STEP_DB_INFO'));
                $view->setMessage($language->getText('ERROR_DB_CONNECT') . " - " . $exception->getMessage());

                throw new SetupControllerExitException();
            } elseif ($exception->getCode() === Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS) {
                $setup->setNextStep($setup->getStep('STEP_DB_INFO'));
                $view->setMessage($exception->getMessage());

                throw new SetupControllerExitException();
            } elseif (($exception->getCode() === Database::ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS)) {
                $setup->setNextStep(null);
                $this->formMessageIfMySqyVersionIsNotRecommended($view, $language);
                $databaseExists = false;
                // check if DB is already UP and running
                if (!$this->databaseCanBeOverwritten($database)) {
                    $this->formMessageIfDBCanBeOverwritten($databaseConfigValues['dbName'], $view, $language);
                    $databaseExists = true;
                }
                $this->formMessageIgnoreDbVersionNotRecommended($view, $language, $session->getSid(), $setup->getStep('STEP_DIRS_INFO'), $databaseExists);

                throw new SetupControllerExitException();
            } else {
                $this->ensureDatabasePresent($database, $databaseConfigValues['dbName']);
            }
        }

        $view->setViewParam("aDB", $databaseConfigValues);

        // check if DB is already UP and running
        if (!$this->databaseCanBeOverwritten($database)) {
            $this->formMessageIfDBCanBeOverwritten($databaseConfigValues['dbName'], $view, $language);
            $this->formMessageInstallAnyway($view, $language, $session->getSid(), $setup->getStep('STEP_DIRS_INFO'));

            throw new SetupControllerExitException();
        }

        $setup->setNextStep($setup->getStep('STEP_DIRS_INFO'));

        $this->view->setTemplateFileName("dbconnect.php");
    }
public function dbConnect ( ) { $ setup = $ this -> getSetupInstance ( ) ; $ session = $ this -> getSessionInstance ( ) ; $ language = $ this -> getLanguageInstance ( ) ; $ view = $ this -> getView ( ) ; $ view -> setTitle ( 'STEP_3_1_TITLE' ) ; $ databaseConfigValues = $ this -> getUtilitiesInstance ( ) -> getRequestVar ( "aDB" , "post" ) ; $ session -> setSessionParam ( 'aDB' , $ databaseConfigValues ) ; // check if important parameters are set if ( ! $ databaseConfigValues [ 'dbHost' ] || ! $ databaseConfigValues [ 'dbName' ] ) { $ setup -> setNextStep ( $ setup -> getStep ( 'STEP_DB_INFO' ) ) ; $ view -> setMessage ( $ language -> getText ( 'ERROR_FILL_ALL_FIELDS' ) ) ; throw new SetupControllerExitException ( ) ; } try { // ok check DB Connection $ database = $ this -> getDatabaseInstance ( ) ; $ database -> openDatabase ( $ databaseConfigValues ) ; } catch ( Exception $ exception ) { if ( $ exception -> getCode ( ) === Database :: ERROR_DB_CONNECT ) { $ setup -> setNextStep ( $ setup -> getStep ( 'STEP_DB_INFO' ) ) ; $ view -> setMessage ( $ language -> getText ( 'ERROR_DB_CONNECT' ) . " - " . $ exception -> getMessage ( ) ) ; throw new SetupControllerExitException ( ) ; } elseif ( $ exception -> getCode ( ) === Database :: ERROR_MYSQL_VERSION_DOES_NOT_FIT_REQUIREMENTS ) { $ setup -> setNextStep ( $ setup -> getStep ( 'STEP_DB_INFO' ) ) ; $ view -> setMessage ( $ exception -> getMessage ( ) ) ; throw new SetupControllerExitException ( ) ; } elseif ( ( $ exception -> getCode ( ) === Database :: ERROR_MYSQL_VERSION_DOES_NOT_FIT_RECOMMENDATIONS ) ) { $ setup -> setNextStep ( null ) ; $ this -> formMessageIfMySqyVersionIsNotRecommended ( $ view , $ language ) ; $ databaseExists = false ; // check if DB is already UP and running if ( ! $ this -> databaseCanBeOverwritten ( $ database ) ) { $ this -> formMessageIfDBCanBeOverwritten ( $ databaseConfigValues [ 'dbName' ] , $ view , $ language ) ; $ databaseExists = true ; } $ this -> formMessageIgnoreDbVersionNotRecommended ( $ view , $ language , $ session -> getSid ( ) , $ setup -> getStep ( 'STEP_DIRS_INFO' ) , $ databaseExists ) ; throw new SetupControllerExitException ( ) ; } else { $ this -> ensureDatabasePresent ( $ database , $ databaseConfigValues [ 'dbName' ] ) ; } } $ view -> setViewParam ( "aDB" , $ databaseConfigValues ) ; // check if DB is already UP and running if ( ! $ this -> databaseCanBeOverwritten ( $ database ) ) { $ this -> formMessageIfDBCanBeOverwritten ( $ databaseConfigValues [ 'dbName' ] , $ view , $ language ) ; $ this -> formMessageInstallAnyway ( $ view , $ language , $ session -> getSid ( ) , $ setup -> getStep ( 'STEP_DIRS_INFO' ) ) ; throw new SetupControllerExitException ( ) ; } $ setup -> setNextStep ( $ setup -> getStep ( 'STEP_DIRS_INFO' ) ) ; $ this -> view -> setTemplateFileName ( "dbconnect.php" ) ; }
Testing database connection

Functionality is tested via:
`Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenNotAllFieldsAreFilled`
`Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenDatabaseUserDoesNotHaveAccess`
`Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenDatabaseUserIsValidButCantCreateDatabase`
`Acceptance/Frontend/ShopSetUpTest.php::testUserIsNotifiedIfAValidDatabaseAlreadyExistsBeforeTryingToOverwriteIt`
Testing database connection