'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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Your Common Sense