No, sorry, my mistake. I just completely read yours wrong, and posted wrong too.
Yes you check the result code for FALSE, I just usually do it a different way, I.e. if ($val==FALSE) {error handling here}
Basically, the way you do it is:
$host="hostname";
$dbname="database";
$user="myname";
$password="mypassword";
$conn = @pg_connect("host=$host dbname=$dbname user=$user password=$password");
if ($conn==FALSE) die("Couldn't connect to database.");
$query = "select * from sometable";
$result = pg_exec($conn,$query);
if ($result==FALSE){
print @pg_errormessage($conn);
mail("a message of doom");
exit;
}
else {do something interesting}
Note that any query that kills a backend will lose it's