catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

how to check connection ? #1051

Closed deawx closed 2 years ago

deawx commented 2 years ago

how to check connection is connect or false message.

deawx commented 2 years ago

OK used


       try {
             $testconnect = new medoo([
                'type' => "mysql",
                'server' => "127.0.0.1",
                'username' => "sa",
                'password' => "",
                'database_name' => "mydatabase",
                'port' => 3306,
                'charset' => "utf8",
            ]);
} catch (PDOException $e) {
            $errors =  $e->getMessage();
            $x = explode(" ", $errors); 
            $a = strlen($x[0]);
            $b = strlen($x[1]);
            $sublen = $a + $b + 1;

echo "ERROR MSG => ".substr($errors, $sublen);
            exit();
        }