Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5350

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Sends asynchronous query</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-send-query-params.html">pg_send_query_params</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-set-client-encoding.html">pg_set_client_encoding</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-send-query" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_send_query</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_send_query</span> &mdash; <span class="dc-title">
   Sends asynchronous query
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-send-query-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>pg_send_query</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>pg_send_query()</strong></span> sends a query or queries asynchronously to the
   <em><code class="parameter">connection</code></em>. Unlike
    <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span>, it can send multiple queries at once to
   PostgreSQL and get the results one by one using
    <span class="function"><a href="function.pg-get-result.html" class="function">pg_get_result()</a></span>.
  </p>
  <p class="para">
   Script execution is not blocked while the queries are executing. Use
    <span class="function"><a href="function.pg-connection-busy.html" class="function">pg_connection_busy()</a></span> to check if the connection is
   busy (i.e. the query is executing). Queries may be cancelled using
    <span class="function"><a href="function.pg-cancel-query.html" class="function">pg_cancel_query()</a></span>.
  </p>
  <p class="para">
   Although the user can send multiple queries at once, multiple queries
   cannot be sent over a busy connection. If a query is sent while
   the connection is busy, it waits until the last query is finished and
   discards all its results.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.pg-send-query-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>

    <dt>

     <span class="term"><em><code class="parameter">query</code></em></span>
     <dd>

      <p class="para">
       The SQL statement or statements to be executed.
      </p>
      <p class="para">
       Data inside the query should be <a href="function.pg-escape-string.html" class="link">properly escaped</a>.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-send-query-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure.</p>
  <p class="para">
   Use  <span class="function"><a href="function.pg-get-result.html" class="function">pg_get_result()</a></span> to determine the query result.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-send-query-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2120">
    <p><strong>Example #1  <span class="function"><strong>pg_send_query()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">pg_connection_busy</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">pg_send_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;authors;&nbsp;select&nbsp;count(*)&nbsp;from&nbsp;authors;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$res1&nbsp;</span><span style="color: #007700">=&nbsp;</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 />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"First&nbsp;call&nbsp;to&nbsp;pg_get_result():&nbsp;</span><span style="color: #0000BB">$res1</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$rows1&nbsp;</span><span style="color: #007700">=&nbsp;</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 />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$res1</span><span style="color: #DD0000">&nbsp;has&nbsp;</span><span style="color: #0000BB">$rows1</span><span style="color: #DD0000">&nbsp;records\n\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$res2&nbsp;</span><span style="color: #007700">=&nbsp;</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 />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Second&nbsp;call&nbsp;to&nbsp;pg_get_result():&nbsp;</span><span style="color: #0000BB">$res2</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$rows2&nbsp;</span><span style="color: #007700">=&nbsp;</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 />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$res2</span><span style="color: #DD0000">&nbsp;has&nbsp;</span><span style="color: #0000BB">$rows2</span><span style="color: #DD0000">&nbsp;records\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</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-send-query-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.pg-query.html" class="function" rel="rdfs-seeAlso">pg_query()</a> - Execute a query</span></li>
    <li class="member"> <span class="function"><a href="function.pg-cancel-query.html" class="function" rel="rdfs-seeAlso">pg_cancel_query()</a> - Cancel an asynchronous query</span></li>
    <li class="member"> <span class="function"><a href="function.pg-get-result.html" class="function" rel="rdfs-seeAlso">pg_get_result()</a> - Get asynchronous query result</span></li>
    <li class="member"> <span class="function"><a href="function.pg-connection-busy.html" class="function" rel="rdfs-seeAlso">pg_connection_busy()</a> - Get connection is busy or not</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-send-query-params.html">pg_send_query_params</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-set-client-encoding.html">pg_set_client_encoding</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>