PHP 5.6.0beta1 released

pg_get_result

(PHP 4 >= 4.2.0, PHP 5)

pg_get_result Retorna o resultado de uma consulta (query) assíncrona

Descrição

resource pg_get_result ([ resource $connection ] )

pg_get_result() retorna o recurso (resource) de resultado de uma consulta (query) executada por ps_send_query(). pg_send_query() pode enviar múltiplas consultas (queries) ao servidor PostgreSQL e pg_get_result() é usada para carregar os resultados das consultas, um por um. Retorna o recurso (resource) de resultado. Se não houverem mais resultados, retorna FALSE.

add a note add a note

User Contributed Notes 3 notes

up
1
william at 25thandClement dot com
9 years ago
There is no way to poll/wait for a notification to come in. You either have to enter a busy loop or sleep. Both options are horrible. It would be nice for PHP to provide access to PQsocket so one could select() on the socket connection. This is how it's done from C or Perl.
up
-1
gullevek at gullevek dot org
6 months ago
To have a a simple wait output with async queries you can use the pg_connection_busy command:

<?php
$dbh
= pg_connect("host=XXX user=XXX password=XXX dbname=XXX");
if (!
$dbh)
{
    print
"Failed to connect";
    exit;
}

$query = "SELECT pg_sleep(10)";
if (!
pg_connection_busy($dbh))
{
   
$sent = pg_send_query($dbh, $query);
    print
"Sent query, waiting: ";
    while (
pg_connection_busy($dbh)
    {
        print
".";
       
flush();
    }
   
$res = pg_get_result($dbh);
    print
"<br>"; // or \n
   
print "Result is: $res";
}

pg_close($dbh);
?>
up
-1
Marko Tiikkaja
5 years ago
william at 25thandClement dot com said: "There is no way to poll/wait for a notification to come in. .."
Yes, there is. If there is a query in progress, pg_get_result() will block and return the result of that query when it's complete.
To Top