php-doc-en/reference/mysqli/functions/mysqli-fetch-array.xml
Georg Richter 8190ee59a5 little docu update
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@150059 c90b9560-bf6c-de11-be94-00142212c4b1
2004-01-28 23:18:42 +00:00

155 lines
5.2 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<refentry id="function.mysqli-fetch-array">
<refnamediv>
<refname>mysqli_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>mysqli_fetch_array</methodname>
<methodparam><type>object</type><parameter>result</parameter></methodparam>
<methodparam choice='opt'><type>int</type><parameter>resulttype</parameter></methodparam>
</methodsynopsis>
<para>Object oriend 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 &false; if there are no more rows for the
database connection represented by the <parameter>link</parameter> parameter.
</para>
<para>
<function>mysqli_fetch_array</function> is an extended version of the
<function>mysqli_fetch_row</function> function. In addition to storing the data in the
numeric indices of the result array, the <function>mysqli_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;
<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>result_type</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 MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. By default the
<function>mysqli_fetch_array</function> function will assume MYSQLI_BOTH for this parameter.
</para>
<para>
By using the MYSQLI_ASSOC constant this function will behave identically to the
<function>mysqli_fetch_assoc</function>, while MYSQLI_NUM will behave identically to the
<function>mysqli_fetch_row</function> function. The final option MYSQLI_BOTH will create a single
array with the attributes of both.
</para>
</refsect1>
<refsect1>
<title>Return values</title>
<para>
Returns an array that corresponds to the fetched row or &false; if there are no more rows in resultset.
</para>
</refsect1>
<refsect1>
<title>Example</title>
<para>
<example>
<title>mysqli_fetch_array with MYSQLI_NUM</title>
<programlisting role="php">
<![CDATA[
<?php
mysqli_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysqli_error());
mysqli_select_db("mydb");
$result = mysqli_query("SELECT id, name FROM mytable");
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
printf ("ID: %s Name: %s", $row[0], $row[1]);
}
mysqli_free_result($result);
?>
]]>
</programlisting>
</example>
<example>
<title>mysqli_fetch_array with MYSQLI_ASSOC</title>
<programlisting role="php">
<![CDATA[
<?php
mysqli_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysqli_error());
mysqli_select_db("mydb");
$result = mysqli_query("SELECT id, name FROM mytable");
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
printf ("ID: %s Name: %s", $row["id"], $row["name"]);
}
mysqli_free_result($result);
?>
]]>
</programlisting>
</example>
<example>
<title>mysqli_fetch_array with MYSQLI_BOTH</title>
<programlisting role="php">
<![CDATA[
<?php
mysqli_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysqli_error());
mysqli_select_db("mydb");
$result = mysqli_query("SELECT id, name FROM mytable");
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
printf ("ID: %s Name: %s", $row[0], $row["name"]);
}
mysqli_free_result($result);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<function>mysqli_fetch_assoc</function>,
<function>mysqli_fetch_row</function>,
<function>mysqli_fetch_object</function>.
</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
-->