note 44963 added to function.pg-send-query

From: Date: Sat, 21 Aug 2004 08:35:12 +0000
Subject: note 44963 added to function.pg-send-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-75051@lists.php.net to get a copy of this message
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!) ---- Manual Page -- http://www.php.net/manual/en/function.pg-send-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44963 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44963&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44963&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75051) next »