Being careful with the comparison operators is not enough:<?phpif (pg_connection_status($link)===PGSQL_CONNECTION_BAD) reconnect($link);?> The reconnect won't be trigged when $link is null.The manual is just wrong, there are three return values: PGSQL_CONNECTION_OK, PGSQL_CONNECTION_BAD, null