2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2007-06-20 22:25:43 +00:00
|
|
|
<!-- $Revision: 1.21 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.pg-fetch-object">
|
2005-03-08 00:06:33 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>pg_fetch_object</refname>
|
|
|
|
<refpurpose>Fetch a row as an object</refpurpose>
|
|
|
|
</refnamediv>
|
2005-03-11 16:03:26 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
|
|
|
<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>
|
2005-04-06 09:04:49 +00:00
|
|
|
<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>string</type><parameter>class_name</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>array</type><parameter>params</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
2005-03-08 00:06:33 +00:00
|
|
|
<para>
|
|
|
|
<function>pg_fetch_object</function> returns an object with
|
2005-04-06 09:04:49 +00:00
|
|
|
properties that correspond to the fetched row's field names. It can optionally
|
|
|
|
instantiate an object of a specific class, and pass parameters to that
|
|
|
|
class's constructor.
|
2005-03-08 00:06:33 +00:00
|
|
|
</para>
|
|
|
|
&database.fetch-null;
|
|
|
|
<para>
|
|
|
|
Speed-wise, the function is identical to
|
2005-04-06 09:04:49 +00:00
|
|
|
<function>pg_fetch_array</function>, and almost as fast as
|
2005-03-08 00:06:33 +00:00
|
|
|
<function>pg_fetch_row</function> (the difference is
|
|
|
|
insignificant).
|
|
|
|
</para>
|
2005-03-11 16:03:26 +00:00
|
|
|
</refsect1>
|
|
|
|
|
2005-04-06 09:04:49 +00:00
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>result</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
PostgreSQL query result resource, returned by <function>pg_query</function>,
|
|
|
|
<function>pg_query_params</function> or <function>pg_execute</function>
|
|
|
|
(among others).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>row</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Row number in result to fetch. Rows are numbered from 0 upwards. If omitted,
|
|
|
|
next row is fetched.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>result_type</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Ignored and deprecated. Defaults to <constant>PGSQL_ASSOC</constant>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>class_name</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The name of the class to instantiate, set the properties of and return.
|
2006-08-31 22:09:10 +00:00
|
|
|
If not specified, a <classname>stdClass</classname> object is returned.
|
2005-04-06 09:04:49 +00:00
|
|
|
</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>
|
|
|
|
An <type>object</type> with one attribute for each field
|
|
|
|
name in the result. Database <literal>NULL</literal>
|
|
|
|
values are returned as &null;.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
&false; is returned if <parameter>row</parameter> exceeds the number
|
|
|
|
of rows in the set, there are no more rows, or on any other error.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-06-11 22:48:10 +00:00
|
|
|
|
|
|
|
<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>
|
|
|
|
<parameter>class_name</parameter> and <parameter>params</parameter>
|
|
|
|
were added. The old form with <parameter>result_type</parameter>
|
|
|
|
still exists for backwards compatibility.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>4.3.0</entry>
|
|
|
|
<entry>
|
|
|
|
<parameter>result_type</parameter> default changed from
|
|
|
|
<constant>PGSQL_BOTH</constant> to <constant>PGSQL_ASSOC</constant>,
|
|
|
|
since the numeric index was illegal.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>4.1.0</entry>
|
|
|
|
<entry>
|
|
|
|
The parameter <parameter>row</parameter> became optional.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2005-03-11 16:03:26 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2005-03-08 00:06:33 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>pg_fetch_object</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
2003-07-16 09:20:01 +00:00
|
|
|
$database = "store";
|
2002-04-15 00:12:54 +00:00
|
|
|
|
2003-07-16 09:20:01 +00:00
|
|
|
$db_conn = pg_connect("host=localhost port=5432 dbname=$database");
|
|
|
|
if (!$db_conn) {
|
2005-03-08 00:06:33 +00:00
|
|
|
echo "Failed connecting to postgres database $database\n";
|
|
|
|
exit;
|
2002-04-15 00:12:54 +00:00
|
|
|
}
|
|
|
|
|
2003-07-16 09:20:01 +00:00
|
|
|
$qu = pg_query($db_conn, "SELECT * FROM books ORDER BY author");
|
|
|
|
|
|
|
|
|
2005-05-09 01:36:07 +00:00
|
|
|
while ($data = pg_fetch_object($qu)) {
|
2005-03-08 00:06:33 +00:00
|
|
|
echo $data->author . " (";
|
|
|
|
echo $data->year . "): ";
|
|
|
|
echo $data->title . "<br />";
|
2002-04-15 00:12:54 +00:00
|
|
|
}
|
2003-07-16 09:20:01 +00:00
|
|
|
|
2003-12-15 16:55:22 +00:00
|
|
|
pg_free_result($qu);
|
|
|
|
pg_close($db_conn);
|
2003-07-16 09:20:01 +00:00
|
|
|
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2005-03-08 00:06:33 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2005-03-11 16:03:26 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
<simplelist>
|
|
|
|
<member><function>pg_query</function></member>
|
|
|
|
<member><function>pg_fetch_array</function></member>
|
|
|
|
<member><function>pg_fetch_assoc</function></member>
|
|
|
|
<member><function>pg_fetch_row</function></member>
|
|
|
|
<member><function>pg_fetch_result</function></member>
|
|
|
|
</simplelist>
|
2005-03-08 00:06:33 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- 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
|
|
|
|
-->
|