We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to check database connection success with Phalcon?

Hi, I want check database connection in Install website script. I use this code in InstallController But this is slowly. Do you have another solution?

//I use this code in InstallController
try {
    $this->db->connect();
    $this->view->setVar('db_connect', 1);
    //Execute sql backup base database
} catch (\Exception $e) {
    $this->view->setVar('db_connect', 0);
    //Display view config
}


2.5k
Accepted
answer

Because $config->host is empty => time response slowly. Now I set default is 'localhost' :)