<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pgsql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.pg-fetch-all.php',
    1 => 'pg_fetch_all',
    2 => 'Fetches all rows from a result as an array',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL Functions',
  ),
  'prev' => 
  array (
    0 => 'function.pg-execute.php',
    1 => 'pg_execute',
  ),
  'next' => 
  array (
    0 => 'function.pg-fetch-all-columns.php',
    1 => 'pg_fetch_all_columns',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pgsql/functions/pg-fetch-all.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-fetch-all" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_fetch_all</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_fetch_all</span> &mdash; <span class="dc-title">Fetches all rows from a result as an array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-fetch-all-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_fetch_all</strong></span>(<span class="methodparam"><span class="type"><a href="class.pgsql-result.php" class="type PgSql\Result">PgSql\Result</a></span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$mode</code><span class="initializer"> = <strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong></span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_fetch_all()</strong></span> returns an array that
   contains all rows (records) in the <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span> instance.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function sets NULL fields to
the PHP <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> value.</span></p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-fetch-all-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">result</code></dt>
     <dd>
      <p class="para">An <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span> instance, returned by <span class="function"><a href="function.pg-query.php" class="function">pg_query()</a></span>,
<span class="function"><a href="function.pg-query-params.php" class="function">pg_query_params()</a></span> or <span class="function"><a href="function.pg-execute.php" class="function">pg_execute()</a></span>(among others).</p>
     </dd>
    
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
An optional parameter that controls how the returned <span class="type"><a href="language.types.array.php" class="type array">array</a></span> is indexed.
<code class="parameter">mode</code> is a constant and can take the following values:
<strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong>, <strong><code><a href="pgsql.constants.php#constant.pgsql-num">PGSQL_NUM</a></code></strong> and <strong><code><a href="pgsql.constants.php#constant.pgsql-both">PGSQL_BOTH</a></code></strong>.
Using <strong><code><a href="pgsql.constants.php#constant.pgsql-num">PGSQL_NUM</a></code></strong>, the function will return an array with numerical indices,
using <strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong> it will return only associative indices
while <strong><code><a href="pgsql.constants.php#constant.pgsql-both">PGSQL_BOTH</a></code></strong> will return both numerical and associative indices.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-fetch-all-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   An <span class="type"><a href="language.types.array.php" class="type array">array</a></span> with all rows in the result.  Each row is an array
   of field values indexed by field name.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-fetch-all-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
 <td>8.1.0</td>
 <td>
  The <code class="parameter">result</code> parameter expects an <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>
  instance now; previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was expected.
 </td>
</tr>

      <tr>
       <td>8.0.0</td>
       <td>
        <span class="function"><strong>pg_fetch_all()</strong></span> will now return an empty <span class="type"><a href="language.types.array.php" class="type array">array</a></span>
        instead of <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> for result sets with zero rows.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        The <code class="parameter">mode</code> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-fetch-all-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 PostgreSQL fetch all</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php <br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"An error occurred.\n"</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT * FROM authors"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"An error occurred.\n"</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #0000BB">$arr </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_fetch_all</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
     <div class="examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Array
        (
            [id] =&gt; 1
            [name] =&gt; Fred
        )

    [1] =&gt; Array
        (
            [id] =&gt; 2
            [name] =&gt; Bob
        )

)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-fetch-all-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-fetch-row.php" class="function" rel="rdfs-seeAlso">pg_fetch_row()</a> - Get a row as an enumerated array</span></li>
    <li><span class="function"><a href="function.pg-fetch-array.php" class="function" rel="rdfs-seeAlso">pg_fetch_array()</a> - Fetch a row as an array</span></li>
    <li><span class="function"><a href="function.pg-fetch-object.php" class="function" rel="rdfs-seeAlso">pg_fetch_object()</a> - Fetch a row as an object</span></li>
    <li><span class="function"><a href="function.pg-fetch-result.php" class="function" rel="rdfs-seeAlso">pg_fetch_result()</a> - Returns values from a result instance</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>