<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
<refentry xml:id="function.pg-fetch-object" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>pg_fetch_object</refname>
  <refpurpose>Fetch a row as an object</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type class="union"><type>object</type><type>false</type></type><methodname>pg_fetch_object</methodname>
   <methodparam><type>PgSql\Result</type><parameter>result</parameter></methodparam>
   <methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>row</parameter><initializer>&null;</initializer></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>class</parameter><initializer>"stdClass"</initializer></methodparam>
   <methodparam choice="opt"><type>array</type><parameter>constructor_args</parameter><initializer>[]</initializer></methodparam>
  </methodsynopsis>
  <para>
   <function>pg_fetch_object</function> returns an object with
   properties that correspond to the fetched row's field names.  It can optionally
   instantiate an object of a specific class, and pass parameters to that
   class's constructor.
  </para>
  &database.fetch-null;
  <para>
   Speed-wise, the function is identical to
   <function>pg_fetch_array</function>, and almost as fast as
   <function>pg_fetch_row</function> (the difference is
   insignificant).
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>result</parameter></term>
     <listitem>
      &pgsql.parameter.result;
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>row</parameter></term>
     <listitem>
      <para>
       Row number in result to fetch. Rows are numbered from 0 upwards. If
       omitted or &null;, the next row is fetched.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>class</parameter></term>
      <listitem>
       <para>
        The name of the class to instantiate, set the properties of and return.
        If not specified, a <classname>stdClass</classname> object is returned.
       </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>constructor_args</parameter></term>
      <listitem>
       <para>
        An optional <type>array</type> of parameters to pass to the constructor
        for <parameter>class</parameter> objects.
       </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   An <type>object</type> with one attribute for each field
   name in the result.  Database <literal>NULL</literal>
   values are returned as &null;.
  </para>
  <para>
   &false; is returned if <parameter>row</parameter> exceeds the number
   of rows in the set, there are no more rows, or on any other error.
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     &pgsql.changelog.result-object;
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>pg_fetch_object</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php 

$database = "store";

$db_conn = pg_connect("host=localhost port=5432 dbname=$database");
if (!$db_conn) {
  echo "Failed connecting to postgres database $database\n";
  exit;
}

$qu = pg_query($db_conn, "SELECT * FROM books ORDER BY author");


while ($data = pg_fetch_object($qu)) {
  echo $data->author . " (";
  echo $data->year . "): ";
  echo $data->title . "<br />";
}

pg_free_result($qu);
pg_close($db_conn);

?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>pg_query</function></member>
    <member><function>pg_fetch_array</function></member>
    <member><function>pg_fetch_assoc</function></member>
    <member><function>pg_fetch_row</function></member>
    <member><function>pg_fetch_result</function></member>
   </simplelist>
  </para>
 </refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
