php-doc-en/reference/pgsql/functions/pg-fetch-object.xml
2004-07-26 14:02:10 +00:00

124 lines
3.6 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
<refentry id="function.pg-fetch-object">
<refnamediv>
<refname>pg_fetch_object</refname>
<refpurpose>Fetch a row as an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>object</type><methodname>pg_fetch_object</methodname>
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>row</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>result_type</parameter></methodparam>
</methodsynopsis>
<para>
<function>pg_fetch_object</function> returns an object with
properties that correspond to the fetched row. It returns &false;
if there are no more rows or error.
</para>
<para>
<function>pg_fetch_object</function> is similar to
<function>pg_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.fetch-null;
<para>
<parameter>row</parameter> is row (record) number to be
retrieved. First row is 0.
</para>
<para>
Speed-wise, the function is identical to
<function>pg_fetch_array</function>, and almost as quick as
<function>pg_fetch_row</function> (the difference is
insignificant).
</para>
<note>
<para>
From 4.1.0, <parameter>row</parameter> is optional.
</para>
<para>
From 4.3.0, <parameter>result_type</parameter> is default to PGSQL_ASSOC while
older versions' default was PGSQL_BOTH. There is no use for numeric property,
since numeric property name is invalid in PHP.
</para>
<para>
<parameter>result_type</parameter> may be deleted in future versions.
</para>
</note>
<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");
$row = 0; // postgres needs a row counter
while ($data = pg_fetch_object($qu, $row)) {
echo $data->author . " (";
echo $data->year . "): ";
echo $data->title . "<br />";
$row++;
}
pg_free_result($qu);
pg_close($db_conn);
?>
]]>
</programlisting>
</example>
</para>
<note>
<para>
From 4.1.0, <parameter>row</parameter> became optional.
Calling <function>pg_fetch_object</function> will increment
internal row counter counter by 1.
</para>
</note>
<para>
See also
<function>pg_query</function>,
<function>pg_fetch_array</function>,
<function>pg_fetch_assoc</function>,
<function>pg_fetch_row</function> and
<function>pg_fetch_result</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
-->