mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-19 18:38:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@186052 c90b9560-bf6c-de11-be94-00142212c4b1
194 lines
5.6 KiB
XML
194 lines
5.6 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.18 $ -->
|
|
<!-- 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 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>
|
|
<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>
|
|
<para>
|
|
<function>pg_fetch_object</function> returns an object with
|
|
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.
|
|
</para>
|
|
&database.fetch-null;
|
|
<para>
|
|
Speed-wise, the function is identical to
|
|
<function>pg_fetch_array</function>, and almost as fast as
|
|
<function>pg_fetch_row</function> (the difference is
|
|
insignificant).
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<parameter>row</parameter> became optional in PHP 4.1.0.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<parameter>result_type</parameter> default changed from <constant>PGSQL_BOTH</constant>
|
|
to <constant>PGSQL_ASSOC</constant> from PHP 4.3.0, since the numeric index was
|
|
illegal.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
<parameter>class_name</parameter> and <parameter>params</parameter> were
|
|
added in PHP 5.0. The old form with <parameter>result_type</parameter>
|
|
still exists for backwards compatibility.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<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.
|
|
If not specified, an <literal>stdClass</literal> 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>
|
|
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>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<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");
|
|
|
|
|
|
while ($data = pg_fetch_object($qu)) {
|
|
echo $data->author . " (";
|
|
echo $data->year . "): ";
|
|
echo $data->title . "<br />";
|
|
}
|
|
|
|
pg_free_result($qu);
|
|
pg_close($db_conn);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</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>
|
|
</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
|
|
-->
|