public function checkMysqlConnection($host, $db, $user, $pass)
    {
        $results                        = array();
        $isConnected                    = 0;
        $isDatabaseExists               = 0;
        $isDatabaseCollationNameValid   = 0;
        $isPassCorrect                  = 1;

        if($this->isDomainExists($host)) {
            $isConnected = 1;

            try {
                $dbAdapter = new DbAdapter(array(
                    'driver' =>  'Pdo',
                    'dsn'   =>   'mysql:dbname=INFORMATION_SCHEMA;host='.$host,
                    'username' => $user,
                    'password' => $pass,
                    'driver_options' => array(
                        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
                    ),
                ));

                $sql = new Sql($dbAdapter);
                $select = $sql->select();
                $select->from('SCHEMATA');
                $select->where(array('SCHEMA_NAME' => $db));

                $statement = $sql->prepareStatementForSqlObject($select);
                $result = $statement->execute();

                $schema = $result->current();
                if(!empty($schema)) {

                    $isDatabaseExists = 1;

                    if (!empty($schema['DEFAULT_COLLATION_NAME']) && $schema['DEFAULT_COLLATION_NAME'] === 'utf8_general_ci') {
                        $isDatabaseCollationNameValid = 1;
                    }
                }
            }catch(\Exception $e) {
                $isPassCorrect = 0;
            }
        }

        $results = array(
            'isConnected' => $isConnected,
            'isDatabaseExists' => $isDatabaseExists,
            'isMysqlPasswordCorrect' => $isPassCorrect,
            'isDatabaseCollationNameValid' => $isDatabaseCollationNameValid,
        );


        return $results;
    }
public function checkMysqlConnection($host, $db, $user, $pass)
    {
        $results                        = array();
        $isConnected                    = 0;
        $isDatabaseExists               = 0;
        $isDatabaseCollationNameValid   = 0;
        $isPassCorrect                  = 1;

        if($this->isDomainExists($host)) {
            $isConnected = 1;

            try {
                $dbAdapter = new DbAdapter(array(
                    'driver' =>  'Pdo',
                    'dsn'   =>   'mysql:dbname=INFORMATION_SCHEMA;host='.$host,
                    'username' => $user,
                    'password' => $pass,
                    'driver_options' => array(
                        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
                    ),
                ));

                $sql = new Sql($dbAdapter);
                $select = $sql->select();
                $select->from('SCHEMATA');
                $select->where(array('SCHEMA_NAME' => $db));

                $statement = $sql->prepareStatementForSqlObject($select);
                $result = $statement->execute();

                $schema = $result->current();
                if(!empty($schema)) {

                    $isDatabaseExists = 1;

                    if (!empty($schema['DEFAULT_COLLATION_NAME']) && $schema['DEFAULT_COLLATION_NAME'] === 'utf8_general_ci') {
                        $isDatabaseCollationNameValid = 1;
                    }
                }
            }catch(\Exception $e) {
                $isPassCorrect = 0;
            }
        }

        $results = array(
            'isConnected' => $isConnected,
            'isDatabaseExists' => $isDatabaseExists,
            'isMysqlPasswordCorrect' => $isPassCorrect,
            'isDatabaseCollationNameValid' => $isDatabaseCollationNameValid,
        );


        return $results;
    }
public function checkMysqlConnection ( $ host , $ db , $ user , $ pass ) { $ results = array ( ) ; $ isConnected = 0 ; $ isDatabaseExists = 0 ; $ isDatabaseCollationNameValid = 0 ; $ isPassCorrect = 1 ; if ( $ this -> isDomainExists ( $ host ) ) { $ isConnected = 1 ; try { $ dbAdapter = new DbAdapter ( array ( 'driver' => 'Pdo' , 'dsn' => 'mysql:dbname=INFORMATION_SCHEMA;host=' . $ host , 'username' => $ user , 'password' => $ pass , 'driver_options' => array ( PDO :: MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'" ) , ) ) ; $ sql = new Sql ( $ dbAdapter ) ; $ select = $ sql -> select ( ) ; $ select -> from ( 'SCHEMATA' ) ; $ select -> where ( array ( 'SCHEMA_NAME' => $ db ) ) ; $ statement = $ sql -> prepareStatementForSqlObject ( $ select ) ; $ result = $ statement -> execute ( ) ; $ schema = $ result -> current ( ) ; if ( ! empty ( $ schema ) ) { $ isDatabaseExists = 1 ; if ( ! empty ( $ schema [ 'DEFAULT_COLLATION_NAME' ] ) && $ schema [ 'DEFAULT_COLLATION_NAME' ] === 'utf8_general_ci' ) { $ isDatabaseCollationNameValid = 1 ; } } } catch ( \ Exception $ e ) { $ isPassCorrect = 0 ; } } $ results = array ( 'isConnected' => $ isConnected , 'isDatabaseExists' => $ isDatabaseExists , 'isMysqlPasswordCorrect' => $ isPassCorrect , 'isDatabaseCollationNameValid' => $ isDatabaseCollationNameValid , ) ; return $ results ; }
Checks if your MySql is working and if your database is existing
@param string $host
@param string $db
@param string $user
@param string $pass
@return Json
Checks if your MySql is working and if your database is existing