<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Get asynchronous query result</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-get-pid.html">pg_get_pid</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-host.html">pg_host</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.pg-get-result" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_get_result</h1> <p class="verinfo">(PHP 4 >= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_get_result</span> — <span class="dc-title"> Get asynchronous query result </span></p> </div> <div class="refsect1 description" id="refsect1-function.pg-get-result-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>pg_get_result</strong></span> ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>pg_get_result()</strong></span> gets the result resource from an asynchronous query executed by <span class="function"><a href="function.pg-send-query.html" class="function">pg_send_query()</a></span>, <span class="function"><a href="function.pg-send-query-params.html" class="function">pg_send_query_params()</a></span> or <span class="function"><a href="function.pg-send-execute.html" class="function">pg_send_execute()</a></span>. </p> <p class="para"> <span class="function"><a href="function.pg-send-query.html" class="function">pg_send_query()</a></span> and the other asynchronous query functions can send multiple queries to a PostgreSQL server and <span class="function"><strong>pg_get_result()</strong></span> is used to get each query's results, one by one. </p> </div> <div class="refsect1 parameters" id="refsect1-function.pg-get-result-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">connection</code></em></span> <dd> <p class="para"> PostgreSQL database connection resource. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-get-result-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The result <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>, or <strong><code>FALSE</code></strong> if no more results are available. </p> </div> <div class="refsect1 examples" id="refsect1-function.pg-get-result-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2082"> <p><strong>Example #1 <span class="function"><strong>pg_get_result()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $dbconn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">) or die(</span><span style="color: #DD0000">"Could not connect"</span><span style="color: #007700">);<br /><br /> if (!</span><span style="color: #0000BB">pg_connection_busy</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">pg_send_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">, </span><span style="color: #DD0000">"select * from authors; select count(*) from authors;"</span><span style="color: #007700">);<br /> }<br /> <br /> </span><span style="color: #0000BB">$res1 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_get_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"First call to pg_get_result(): </span><span style="color: #0000BB">$res1</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$rows1 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$res1</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$res1</span><span style="color: #DD0000"> has </span><span style="color: #0000BB">$rows1</span><span style="color: #DD0000"> records\n\n"</span><span style="color: #007700">;<br /> <br /> </span><span style="color: #0000BB">$res2 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_get_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"Second call to pg_get_result(): </span><span style="color: #0000BB">$res2</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$rows2 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$res2</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$res2</span><span style="color: #DD0000"> has </span><span style="color: #0000BB">$rows2</span><span style="color: #DD0000"> records\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> First call to pg_get_result(): Resource id #3 Resource id #3 has 3 records Second call to pg_get_result(): Resource id #4 Resource id #4 has 1 records </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.pg-get-result-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.pg-send-query.html" class="function" rel="rdfs-seeAlso">pg_send_query()</a> - Sends asynchronous query</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-get-pid.html">pg_get_pid</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-host.html">pg_host</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>