Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 5760

php-manual-en-7.2.11-1.mga7.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>Fetch a row as an object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-fetch-assoc.html">pg_fetch_assoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-fetch-result.html">pg_fetch_result</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-fetch-object" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_fetch_object</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</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">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">object</span> <span class="methodname"><strong>pg_fetch_object</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$result_type</code><span class="initializer"> = PGSQL_ASSOC</span></span>
  ]] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">object</span> <span class="methodname"><strong>pg_fetch_object</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$class_name</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$params</code></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">Note</strong>: <span class="simpara">This function sets NULL fields to
the PHP <strong><code>NULL</code></strong> value.</span></p></blockquote>
  <p class="para">
   Speed-wise, the function is identical to
   <span class="function"><a href="function.pg-fetch-array.html" class="function">pg_fetch_array()</a></span>, and almost as fast as
   <span class="function"><a href="function.pg-fetch-row.html" 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">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">result</code></dt>

     <dd>

      <p class="para">
       PostgreSQL query result resource, returned by <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span>,
       <span class="function"><a href="function.pg-query-params.html" class="function">pg_query_params()</a></span> or <span class="function"><a href="function.pg-execute.html" class="function">pg_execute()</a></span>
       (among others).
      </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>NULL</code></strong>, the next row is fetched.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">result_type</code></dt>

      <dd>

       <p class="para">
        Ignored and deprecated.
       </p>
     </dd>

    
    
     <dt>
<code class="parameter">class_name</code></dt>

      <dd>

       <p class="para">
        The name of the class to instantiate, set the properties of and return.
        If not specified, a <strong class="classname">stdClass</strong> object is returned.
       </p>
     </dd>

    
    
     <dt>
<code class="parameter">params</code></dt>

      <dd>

       <p class="para">
        An optional <span class="type"><a href="language.types.array.html" class="type array">array</a></span> of parameters to pass to the constructor
        for <code class="parameter">class_name</code> objects.
       </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-fetch-object-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   An <span class="type"><a href="language.types.object.html" class="type object">object</a></span> with one attribute for each field
   name in the result.  Database <em>NULL</em>
   values are returned as <strong><code>NULL</code></strong>.
  </p>
  <p class="para">
   <strong><code>FALSE</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 examples" id="refsect1-function.pg-fetch-object-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2547">
    <p><strong>Example #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&nbsp;<br /><br />$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"store"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$db_conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=localhost&nbsp;port=5432&nbsp;dbname=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$db_conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Failed&nbsp;connecting&nbsp;to&nbsp;postgres&nbsp;database&nbsp;</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$qu&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db_conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;books&nbsp;ORDER&nbsp;BY&nbsp;author"</span><span style="color: #007700">);<br /><br /><br />while&nbsp;(</span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$qu</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">author&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&nbsp;("</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">year&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"):&nbsp;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">title&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&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">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-fetch-array.html" class="function" rel="rdfs-seeAlso">pg_fetch_array()</a> - Fetch a row as an array</span></li>
    <li class="member"><span class="function"><a href="function.pg-fetch-assoc.html" class="function" rel="rdfs-seeAlso">pg_fetch_assoc()</a> - Fetch a row as an associative array</span></li>
    <li class="member"><span class="function"><a href="function.pg-fetch-row.html" class="function" rel="rdfs-seeAlso">pg_fetch_row()</a> - Get a row as an enumerated array</span></li>
    <li class="member"><span class="function"><a href="function.pg-fetch-result.html" class="function" rel="rdfs-seeAlso">pg_fetch_result()</a> - Returns values from a result resource</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-fetch-assoc.html">pg_fetch_assoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-fetch-result.html">pg_fetch_result</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>