php-doc-en/reference/mysql/functions/mysql-fetch-object.xml
Damien Seguy a06eea9818 adding example tag
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@169451 c90b9560-bf6c-de11-be94-00142212c4b1
2004-09-28 15:23:31 +00:00

100 lines
2.7 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- 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;
&database.fetch-null;
<para>
<example>
<title><function>mysql_fetch_object</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$row = mysql_fetch_object($result);
/* this is valid */
echo $row->field;
/* this is invalid */
// echo $row->0;
?>
]]>
</programlisting>
</example>
</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>,
<function>mysql_fetch_row</function>,
<function>mysql_data_seek</function> and
<function>mysql_query</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
-->