简体   繁体   中英

What's the PostgreSQL equivalent of $mysqli->connect_error?

If mysqli error is thrown while connecting to database, it could be detected as below.

if ($mysqli->connect_error) {
    $this->Session->setFlash(__('Cannot Connect to the host'));
    return;
} 

connect_error does not exist for PostgreSQL.

How could I do this in PostgreSQL? How can I catch the connect error?

Use PDO to connect to PostgreSQL. It will throw an exception on connect error, which is way better than manual checking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM