<?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 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.pg-fetch-object.php',
    1 => 'pg_fetch_object',
    2 => 'Fetch a row as an object',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL Функції',
  ),
  'prev' => 
  array (
    0 => 'function.pg-fetch-assoc.php',
    1 => 'pg_fetch_assoc',
  ),
  'next' => 
  array (
    0 => 'function.pg-fetch-result.php',
    1 => 'pg_fetch_result',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pgsql/functions/pg-fetch-object.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-fetch-object" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_fetch_object</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_fetch_object</span> &mdash; <span class="dc-title">Fetch a row as an object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-fetch-object-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_fetch_object</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<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>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$row</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$class</code><span class="initializer"> = &quot;stdClass&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$constructor_args</code><span class="initializer"> = []</span></span><br>): <span class="type"><span class="type"><a href="language.types.object.php" class="type object">object</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_fetch_object()</strong></span> returns an object with
   properties that correspond to the fetched row&#039;s field names.  It can optionally
   instantiate an object of a specific class, and pass parameters to that
   class&#039;s constructor.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: <span class="simpara">Ця функція встановлює
NULL-полям значення PHP <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.</span></p></blockquote>
  <p class="para">
   Speed-wise, the function is identical to
   <span class="function"><a href="function.pg-fetch-array.php" class="function">pg_fetch_array()</a></span>, and almost as fast as
   <span class="function"><a href="function.pg-fetch-row.php" class="function">pg_fetch_row()</a></span> (the difference is
   insignificant).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-fetch-object-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">result</code></dt>
     <dd>
      <p class="para">Примірник
<span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>, якого повертає одна з функцій
<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> або
<span class="function"><a href="function.pg-execute.php" class="function">pg_execute()</a></span> (серед інших).</p>
     </dd>
    
    
     <dt><code class="parameter">row</code></dt>
     <dd>
      <p class="para">
       Row number in result to fetch. Rows are numbered from 0 upwards. If
       omitted or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the next row is fetched.
      </p>
     </dd>
    
    
     <dt><code class="parameter">class</code></dt>
      <dd>
       <p class="para">
        The name of the class to instantiate, set the properties of and return.
        If not specified, a <span class="classname"><a href="class.stdclass.php" class="classname">stdClass</a></span> object is returned.
       </p>
     </dd>
    
    
     <dt><code class="parameter">constructor_args</code></dt>
      <dd>
       <p class="para">
        An optional <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of parameters to pass to the constructor
        for <code class="parameter">class</code> objects.
       </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-fetch-object-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   An <span class="type"><a href="language.types.object.php" class="type object">object</a></span> with one attribute for each field
   name in the result.  Database <code class="literal">NULL</code>
   values are returned as <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
  <p class="para">
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned if <code class="parameter">row</code> exceeds the number
   of rows in the set, there are no more rows, or on any other error.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.pg-fetch-object-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="para">
   A <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown when
   the <code class="parameter">constructor_args</code> is non-empty with the class not having constructor.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-fetch-object-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Now throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> exception when
       the <code class="parameter">constructor_args</code> is non-empty with the class not having constructor;
       previously an <span class="classname"><a href="class.exception.php" class="classname">Exception</a></span> was thrown.
      </td>
     </tr>

     <tr>
 <td>8.1.0</td>
 <td>
  Тепер параметр <code class="parameter">result</code> має бути примірником
  <span class="classname"><a href="class.pgsql-result.php" class="classname">PgSql\Result</a></span>. Раніше очікувався <a href="language.types.resource.php" class="link">resource</a>.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-fetch-object-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>pg_fetch_object()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php <br /><br />$database </span><span style="color: #007700">= </span><span style="color: #DD0000">"store"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$db_conn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=localhost port=5432 dbname=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$db_conn</span><span style="color: #007700">) {<br />  echo </span><span style="color: #DD0000">"Failed connecting to postgres database </span><span style="color: #0000BB">$database</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />  exit;<br />}<br /><br /></span><span style="color: #0000BB">$qu </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db_conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT * FROM books ORDER BY author"</span><span style="color: #007700">);<br /><br /><br />while (</span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$qu</span><span style="color: #007700">)) {<br />  echo </span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">author </span><span style="color: #007700">. </span><span style="color: #DD0000">" ("</span><span style="color: #007700">;<br />  echo </span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">year </span><span style="color: #007700">. </span><span style="color: #DD0000">"): "</span><span style="color: #007700">;<br />  echo </span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">title </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br /&gt;"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">pg_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$qu</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">pg_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$db_conn</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-fetch-object-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-query.php" class="function" rel="rdfs-seeAlso">pg_query()</a> - Execute a query</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-assoc.php" class="function" rel="rdfs-seeAlso">pg_fetch_assoc()</a> - Fetch a row as an associative array</span></li>
    <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-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); ?>