php-doc-en/reference/maxdb/functions/maxdb-fetch-array.xml
2010-05-09 03:09:46 +00:00

189 lines
5.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.maxdb-fetch-array">
<refnamediv>
<refname>maxdb_fetch_array</refname>
<refname>maxdb_result::fetch_array</refname>
<refpurpose>Fetch a result row as an associative, a numeric array, or both</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<para>&style.procedural;</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>&style.oop;</para>
<methodsynopsis>
<type>mixed</type><methodname>maxdb_result::fetch_array</methodname>
<methodparam choice='opt'><type>int</type><parameter>resulttype</parameter></methodparam>
</methodsynopsis>
<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 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns an array that corresponds to the fetched row or &null; if there are no more rows in resultset.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<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>
&example.outputs.similar;
<screen>
<![CDATA[
New York (NY)
New York (NY)
Long Island (NY)
]]>
</screen>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>maxdb_fetch_assoc</function></member>
<member><function>maxdb_fetch_row</function></member>
<member><function>maxdb_fetch_resource</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:"~/.phpdoc/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
-->