<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.6 $ --> <!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 --> <refentry id="function.mysql-fetch-object"> <refnamediv> <refname>mysql_fetch_object</refname> <refpurpose>Fetch a result row as an object</refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>object</type><methodname>mysql_fetch_object</methodname> <methodparam><type>resource</type><parameter>result</parameter></methodparam> </methodsynopsis> <para> Returns an object with properties that correspond to the fetched row, or &false; if there are no more rows. </para> <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> &database.field-case; <para> <programlisting role="php"> <![CDATA[ <?php /* this is valid */ echo $row->field; /* this is invalid */ echo $row->0; ?> ]]> </programlisting> </para> <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). <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> See also <function>mysql_fetch_array</function>, <function>mysql_fetch_assoc</function> and <function>mysql_fetch_row</function>. </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:"../../../../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 -->