php-doc-en/reference/mysql/functions/mysql-fetch-object.xml
Hannes Magnusson c030e2adf7 Upgrade to DocBook5:
- All id attributes are now xml:id
 - Add docbook namespace to all root elements
 - Replace <ulink /> with <link xlink:href />
 - Minor markup fixes here and there


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@238160 c90b9560-bf6c-de11-be94-00142212c4b1
2007-06-20 22:25:43 +00:00

187 lines
4.8 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.17 $ -->
<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>
<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>
<para>
<function>mysql_fetch_row</function> fetches one row of data from
the result associated with the specified result identifier. The
row is returned as an array. Each result column is stored in an
array offset, starting at offset 0.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.0.0</entry>
<entry>
Added the ability to return as a different object.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</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
$row = mysql_fetch_object($result);
/* this is valid */
echo $row->field;
/* this is invalid */
// echo $row->0;
?>
]]>
</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:"../../../../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
-->