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@172550 c90b9560-bf6c-de11-be94-00142212c4b1
177 lines
5.6 KiB
XML
177 lines
5.6 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.20 $ -->
|
|
<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>mysqli_result</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>mysqli_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>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;
|
|
&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 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>
|
|
&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>
|
|
&reftitle.seealso;
|
|
<para>
|
|
<function>mysqli_fetch_assoc</function>,
|
|
<function>mysqli_fetch_row</function>,
|
|
<function>mysqli_fetch_object</function>,
|
|
<function>mysqli_query</function>&listendand;
|
|
<function>mysqli_data_seek</function>.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1>
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Object oriented style</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
|
|
|
|
/* check connection */
|
|
if (mysqli_connect_errno()) {
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
exit();
|
|
}
|
|
|
|
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
|
|
$result = $mysqli->query($query);
|
|
|
|
/* numeric array */
|
|
$row = $result->fetch_array(MYSQLI_NUM);
|
|
printf ("%s (%s)\n", $row[0], $row[1]);
|
|
|
|
/* associative array */
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
|
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
|
|
|
|
/* associative and numeric array */
|
|
$row = $result->fetch_array(MYSQLI_BOTH);
|
|
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
|
|
|
|
/* free result set */
|
|
$result->close();
|
|
|
|
/* close connection */
|
|
$mysqli->close();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Procedural style</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
|
|
|
|
/* check connection */
|
|
if (mysqli_connect_errno()) {
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
exit();
|
|
}
|
|
|
|
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
|
|
$result = mysqli_query($link, $query);
|
|
|
|
/* numeric array */
|
|
$row = mysqli_fetch_array($result, MYSQLI_NUM);
|
|
printf ("%s (%s)\n", $row[0], $row[1]);
|
|
|
|
/* associative array */
|
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
|
|
|
|
/* associative and numeric array */
|
|
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
|
|
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
|
|
|
|
/* free result set */
|
|
mysqli_free_result($result);
|
|
|
|
/* close connection */
|
|
mysqli_close($link);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Kabul (AFG)
|
|
Qandahar (AFG)
|
|
Herat (AFG)
|
|
]]>
|
|
</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
|
|
-->
|