php-doc-en/reference/maxdb/functions/maxdb-fetch-array.xml
Thomas Simenec ad2d322256 Update documentation
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@181642 c90b9560-bf6c-de11-be94-00142212c4b1
2005-03-08 16:39:06 +00:00

188 lines
6 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<refentry id="function.maxdb-fetch-array">
<refnamediv>
<refname>maxdb_fetch_array</refname>
<refname>result->fetch_array</refname>
<refpurpose>Fetch a result row as an associative, a numeric array, or both</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>mixed</type><methodname>maxdb_fetch_array</methodname>
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
<methodparam choice='opt'><type>int</type><parameter>resulttype</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (method):</para>
<classsynopsis>
<ooclass><classname>result</classname></ooclass>
<methodsynopsis>
<type>mixed</type>
<methodname>fetch_array</methodname>
<methodparam choice='opt'><type>int</type><parameter>resulttype</parameter></methodparam>
</methodsynopsis>
</classsynopsis>
<para>
Returns an array that corresponds to the fetched row or &null; if there are no more rows for the
resultset represented by the <parameter>result</parameter> parameter.
</para>
<para>
<function>maxdb_fetch_array</function> is an extended version of the
<function>maxdb_fetch_row</function> function. In addition to storing the data in the
numeric indices of the result array, the <function>maxdb_fetch_array</function> function can
also store the data in associative indices, using the field names of the result set as keys.
</para>
&database.field-case;
&database.fetch-null;
<para>
If two or more columns of the result have the same field names, the last column will take
precedence and overwrite the earlier data. In order to access multiple columns with the same
name, the numerically indexed version of the row must be used.
</para>
<para>
The optional second argument <parameter>resulttype</parameter> is a constant indicating what
type of array should be produced from the current row data. The possible values for this parameter
are the constants MAXDB_ASSOC, MAXDB_ASSOC_UPPER, MAXDB_ASSOC_LOWER, MAXDB_NUM, or MAXDB_BOTH.
By default the
<function>maxdb_fetch_array</function> function will assume MAXDB_BOTH, which is a combination of
MAXDB_NUM and MAXDB_ASSOC for this parameter.
</para>
<para>
By using the MAXDB_ASSOC constant this function will behave identically to the
<function>maxdb_fetch_assoc</function>, while MAXDB_NUM will behave identically to the
<function>maxdb_fetch_row</function> function. The final option MAXDB_BOTH will create a single
array with the attributes of both.
</para>
<para>
By using the MAXDB_ASSOC_UPPER constant, the behaviour of this function is identical to the use
of MAXDB_ASSOC except the array index of a column is the fieldname in upper case.
</para>
<para>
By using the MAXDB_ASSOC_LOWER constant, the behaviour of this function is identical to the use
of MAXDB_ASSOC except the array index of a column is the fieldname in lower case.
</para>
</refsect1>
<refsect1>
<title>Return values</title>
<para>
Returns an array that corresponds to the fetched row or &null; if there are no more rows in resultset.
</para>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<function>maxdb_fetch_assoc</function>,
<function>maxdb_fetch_row</function>,
<function>maxdb_fetch_resource</function>.
</para>
</refsect1>
<refsect1>
<title>Example</title>
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
$maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
$query = "SELECT name, state FROM hotel.city ORDER by zip";
$result = $maxdb->query($query);
/* numeric array */
$row = $result->fetch_array(MAXDB_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);
/* associative array */
$row = $result->fetch_array(MAXDB_ASSOC);
printf ("%s (%s)\n", $row["NAME"], $row["STATE"]);
/* associative and numeric array */
$row = $result->fetch_array(MAXDB_BOTH);
printf ("%s (%s)\n", $row[0], $row["STATE"]);
/* free result set */
$result->close();
/* close connection */
$maxdb->close();
?>
]]>
</programlisting>
</example>
<example>
<title>Procedural style</title>
<programlisting role="php">
<![CDATA[
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
$query = "SELECT name, state FROM hotel.city ORDER by zip";
$result = maxdb_query($link, $query);
/* numeric array */
$row = maxdb_fetch_array($result, MAXDB_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);
/* associative array */
$row = maxdb_fetch_array($result, MAXDB_ASSOC);
printf ("%s (%s)\n", $row["NAME"], $row["STATE"]);
/* associative and numeric array */
$row = maxdb_fetch_array($result, MAXDB_BOTH);
printf ("%s (%s)\n", $row[0], $row["STATE"]);
/* free result set */
maxdb_free_result($result);
/* close connection */
maxdb_close($link);
?>
]]>
</programlisting>
</example>
<para>
The above examples would produce the following output:
</para>
<screen>
<![CDATA[
New York (NY)
New York (NY)
Long Island (NY)
]]>
</screen>
</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
-->