note 44963 deleted from function.pg-send-query by aidan
| From: | aidan@php.net | Date: | Sat, 21 Aug 2004 09:28:50 +0000 |
| Subject: | note 44963 deleted from function.pg-send-query by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75052@lists.php.net to get a copy of this message | ||
Note Submitter: phpdoc AAATTT badfont DOOOT com :D
----
You can check each result between pg_get_result() calls with pg_result_error(), it seems to return
an empty string "" if there is no error:
<?php
// connect to postgres
if ( ! ($conn = pg_connect("your conn string here")) )
die('Couldnt connect to database!');
// multiple queries (2)
$multiple_query = <<<endheredoc
select * from houses;
select * from tenants;
endheredoc;
if ( ! pg_send_query($multple_query) )
die('Something bad happened to muliple_query!');
// get the first result
$result1 = pg_get_result($conn);
// check for error in result1
if ( "" != ($error = pg_result_error($result1)) )
{
die('Something wrong with result1: ' . $error);
}
else
{
// ... do stuff with result1 then free it when done
pg_free_result($result1);
}
// get the second result
$result2 = pg_get_result($conn);
// check for error in result1
if ( "" != ($error = pg_result_error($result2)) )
{
die('Something wrong with result2: ' . $error);
}
else
{
// ... do stuff with result2 then free it when done
pg_free_result($result2);
}
// close db connection
pg_close($conn)
?>
Sorry for bad coding example but it should illustrate error checking for pg_send_query().
If you don't check for these errors you don't get notified in the same way that you do
pg_query() so it has the potential to confuse you (it confused me for about 10 minutes, I had a
simple syntax error in my SQL!)