<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.mysql-fetch-object" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>mysql_fetch_object</refname>
  <refpurpose>Fetch a result row as an object</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
  <warning>
   &mysql.alternative.note;
   <simplelist role="alternatives">
    <member><function>mysqli_fetch_object</function></member>
    <member>
     <methodname>PDOStatement::fetch</methodname>
     with <parameter>mode</parameter> as <constant>PDO::FETCH_OBJ</constant>
    </member>
   </simplelist>
  </warning>
 </refsynopsisdiv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>object</type><methodname>mysql_fetch_object</methodname>
   <methodparam><type>resource</type><parameter>result</parameter></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>class_name</parameter></methodparam>
   <methodparam choice="opt"><type>array</type><parameter>params</parameter></methodparam>
  </methodsynopsis>
  <para>
   Returns an object with properties that correspond to the fetched row
   and moves the internal data pointer ahead.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    &mysql.result.description;
    <varlistentry>
     <term><parameter>class_name</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>params</parameter></term>
      <listitem>
       <para>
        An optional <type>array</type> of parameters to pass to the constructor
        for <parameter>class_name</parameter> objects.
       </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns an <type>object</type> with string properties that correspond to the
   fetched row, or &false; if there are no more rows.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>mysql_fetch_object</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select * from mytable");
while ($row = mysql_fetch_object($result)) {
    echo $row->user_id;
    echo $row->fullname;
}
mysql_free_result($result);
?>
]]>
    </programlisting>
   </example>
  </para>
  <para>
   <example>
    <title><function>mysql_fetch_object</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php
class foo {
    public $name;
}

mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");

$result = mysql_query("select name from mytable limit 1");
$obj = mysql_fetch_object($result, 'foo');
var_dump($obj);
?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <title>Performance</title>
   <para>
    Speed-wise, the function is identical to
    <function>mysql_fetch_array</function>, and almost as quick as
    <function>mysql_fetch_row</function> (the difference is
    insignificant).
   </para>
  </note>
  <note>
   <para>
    <function>mysql_fetch_object</function> is similar to
    <function>mysql_fetch_array</function>, with one difference - an
    object is returned, instead of an array.  Indirectly, that means
    that you can only access the data by the field names, and not by
    their offsets (numbers are illegal property names).
   </para>
  </note>
  &database.field-case;
  &database.fetch-null;
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>mysql_fetch_array</function></member>
    <member><function>mysql_fetch_assoc</function></member>
    <member><function>mysql_fetch_row</function></member>
    <member><function>mysql_data_seek</function></member>
    <member><function>mysql_query</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
-->
