note 59202 added to function.pg-send-query
| From: | vincentdephily at osu1 dot php dot net | Date: | Tue, 29 Nov 2005 13:25:59 +0000 |
| Subject: | note 59202 added to function.pg-send-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99293@lists.php.net to get a copy of this message | ||
Note that if you send a query without calling pg_get_result() for the previous one (supposing it has
finished and the connection is not busy), the previous query will get discarded.
See for yourself (tested on php4.4.0, postgres8.0.4, Linux/FreeBSD) :
<?
$conn = pg_connect("dbname=template1 host=localhost user=pgsql");
if ($conn === FALSE)
exit("Can't connect to db");
$q = array();
// send some queries
foreach (range(0, 500) as $i)
stack_query($q, $conn, "SELECT 'query $i' AS str;");
// receive them
while (true)
{
$left = stack_query($q, $conn);
echo "$left left... ";
$result = pg_get_result($conn);
if ($left == 0 && $result === FALSE)
break;
$row = pg_fetch_assoc($result);
// depending on race conditions, you wont get all your original queries here.
echo "got $row[str]\n";
}
function stack_query(&$queries, $conn, $sql = FALSE)
{
if ($sql !== FALSE)
$queries[] = $sql;
while (count($queries) && !pg_connection_busy($conn))
pg_send_query($conn, array_shift($queries));
return count($queries) + (pg_connection_busy($conn) ? 1 : 0);
}
?>
You will have to write a higher level of abstraction if you want a "send all queries now,
receive them later" behaviour.
----
Manual Page -- http://www.php.net/manual/en/function.pg-send-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59202
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59202&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59202&report=yes
Search -- http://master.php.net/manage/user-notes.php