note 117984 added to function.pg-get-result

From: Date: Mon, 14 Sep 2015 22:04:53 +0000
Subject: note 117984 added to function.pg-get-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-203779@lists.php.net to get a copy of this message
It might seem that after calling pg_get_result() upon sending just a single query, the connection will not be busy. The correct way is, though, to call extra pg_get_result() in a loop until it returns false [1]. <?php $conn = pg_connect('...', PGSQL_CONNECT_FORCE_NEW); for ($i = 0; $i < 10000; $i++) { $query = 'erroneous query'; if (pg_connection_busy($conn)) { fprintf(STDERR, "Connection is busy\n"); exit(1); } pg_send_query($conn, $query); $res = pg_get_result($conn); if ($res === false) { fprintf(STDERR, "A result was expected\n"); exit(1); } /* The following does not seem necessary for good queries, but is vital for erroneous queries. Commenting the loop out leads to this script fail with the "Connection is busy" error. */ while (pg_get_result($conn)); // result processing... } ?> See http://www.postgresql.org/message-id/flat/gtitqq$26l3$1@news.hub.org#gtitqq$26l3$1@news.hub.org and https://bugs.php.net/bug.php?id=52750 for detailed information. [1] Or, even better, use an asynchronous connection since PHP 5.6. ---- Server IP: 72.52.91.14 Probable Submitter: 89.103.130.98 ---- Manual Page -- http://php.net/manual/en/function.pg-get-result.php Edit -- https://master.php.net/note/edit/117984 Del: integrated -- https://master.php.net/note/delete/117984/integrated Del: useless -- https://master.php.net/note/delete/117984/useless Del: bad code -- https://master.php.net/note/delete/117984/bad+code Del: spam -- https://master.php.net/note/delete/117984/spam Del: non-english -- https://master.php.net/note/delete/117984/non-english Del: in docs -- https://master.php.net/note/delete/117984/in+docs Del: other reasons-- https://master.php.net/note/delete/117984 Reject -- https://master.php.net/note/reject/117984 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203779) next »