2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-07-26 14:02:10 +00:00
|
|
|
<!-- $Revision: 1.9 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
|
|
|
|
<refentry id="function.pg-fetch-array">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>pg_fetch_array</refname>
|
|
|
|
<refpurpose>Fetch a row as an array</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>array</type><methodname>pg_fetch_array</methodname>
|
|
|
|
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
|
2002-08-01 14:41:25 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>row</parameter></methodparam>
|
2002-04-15 00:12:54 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>result_type</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
<function>pg_fetch_array</function> returns an array that
|
|
|
|
corresponds to the fetched row (tuples/records). It returns
|
|
|
|
&false;, if there are no more rows.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<function>pg_fetch_array</function> is an extended version of
|
|
|
|
<function>pg_fetch_row</function>. In addition to storing the
|
|
|
|
data in the numeric indices (field index) to the result array, it
|
|
|
|
also stores the data in associative indices (field name) by
|
|
|
|
default.
|
|
|
|
</para>
|
2004-07-26 14:02:10 +00:00
|
|
|
&database.fetch-null;
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
|
|
|
<parameter>row</parameter> is row (record) number to be
|
|
|
|
retrieved. First row is 0.
|
|
|
|
</para>
|
|
|
|
<para>
|
2003-02-21 23:49:26 +00:00
|
|
|
<parameter>result_type</parameter> is an optional parameter that controls
|
|
|
|
how the return value is initialized.
|
2002-04-15 00:12:54 +00:00
|
|
|
<parameter>result_type</parameter> is a constant and can take the
|
2003-02-21 23:17:32 +00:00
|
|
|
following values: <constant>PGSQL_ASSOC</constant>,
|
|
|
|
<constant>PGSQL_NUM</constant>, and <constant>PGSQL_BOTH</constant>.
|
2002-04-15 00:12:54 +00:00
|
|
|
<function>pg_fetch_array</function> returns associative array
|
2003-02-21 23:49:26 +00:00
|
|
|
that has field name as key for <constant>PGSQL_ASSOC</constant>, field index as key
|
2003-02-21 23:17:32 +00:00
|
|
|
with <constant>PGSQL_NUM</constant> and both field name/index as key with
|
|
|
|
<constant>PGSQL_BOTH</constant>. Default is <constant>PGSQL_BOTH</constant>.
|
2002-04-15 00:12:54 +00:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
<parameter>result_type</parameter> was added in PHP 4.0.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<function>pg_fetch_array</function> is NOT significantly
|
|
|
|
slower than using <function>pg_fetch_row</function>, while it
|
|
|
|
provides a significant ease of use.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
2003-07-16 09:20:01 +00:00
|
|
|
<title><function>pg_fetch_array</function> example</title>
|
2002-04-15 00:12:54 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2003-07-16 09:20:01 +00:00
|
|
|
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
2002-04-15 00:12:54 +00:00
|
|
|
if (!$conn) {
|
|
|
|
echo "An error occured.\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2003-07-16 09:20:01 +00:00
|
|
|
$result = pg_query($conn, "SELECT * FROM authors");
|
2002-04-15 00:12:54 +00:00
|
|
|
if (!$result) {
|
|
|
|
echo "An error occured.\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2003-07-16 09:20:01 +00:00
|
|
|
$arr = pg_fetch_array($result, 0, PGSQL_NUM);
|
2002-04-15 00:12:54 +00:00
|
|
|
echo $arr[0] . " <- array\n";
|
|
|
|
|
2003-07-16 09:20:01 +00:00
|
|
|
$arr = pg_fetch_array($result, 1, PGSQL_ASSOC);
|
2002-04-15 00:12:54 +00:00
|
|
|
echo $arr["author"] . " <- array\n";
|
2003-07-16 09:20:01 +00:00
|
|
|
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
From 4.1.0, <parameter>row</parameter> became optional.
|
2002-04-25 01:07:17 +00:00
|
|
|
Calling <function>pg_fetch_array</function> will increment
|
|
|
|
internal row counter by 1.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</note>
|
2003-07-16 09:20:01 +00:00
|
|
|
<para>
|
|
|
|
See also
|
|
|
|
<function>pg_fetch_row</function>,
|
|
|
|
<function>pg_fetch_object</function> and
|
|
|
|
<function>pg_fetch_result</function>.
|
|
|
|
</para>
|
2002-04-15 00:12:54 +00:00
|
|
|
</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
|
|
|
|
-->
|