2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 08:13:42 +00:00
|
|
|
<!-- $Revision$ -->
|
2008-01-02 13:58:46 +00:00
|
|
|
<refentry xml:id="mysqli-result.fetch-array" xmlns="http://docbook.org/ns/docbook">
|
2007-01-27 17:37:36 +00:00
|
|
|
<refnamediv>
|
2008-01-02 13:58:46 +00:00
|
|
|
<refname>mysqli_result::fetch_array</refname>
|
2007-01-27 17:37:36 +00:00
|
|
|
<refname>mysqli_fetch_array</refname>
|
|
|
|
<refpurpose>Fetch a result row as an associative, a numeric array, or both</refpurpose>
|
|
|
|
</refnamediv>
|
2007-01-28 04:25:58 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2010-05-08 21:20:24 +00:00
|
|
|
<para>&style.oop;</para>
|
2012-01-10 08:41:49 +00:00
|
|
|
<methodsynopsis role="oop">
|
2008-05-29 14:55:32 +00:00
|
|
|
<type>mixed</type><methodname>mysqli_result::fetch_array</methodname>
|
2011-09-30 14:21:51 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>resulttype</parameter><initializer>MYSQLI_BOTH</initializer></methodparam>
|
2008-01-02 13:58:46 +00:00
|
|
|
</methodsynopsis>
|
2010-05-08 21:20:24 +00:00
|
|
|
<para>&style.procedural;</para>
|
2007-01-27 17:37:36 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>mixed</type><methodname>mysqli_fetch_array</methodname>
|
|
|
|
<methodparam><type>mysqli_result</type><parameter>result</parameter></methodparam>
|
2011-09-30 14:21:51 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>resulttype</parameter><initializer>MYSQLI_BOTH</initializer></methodparam>
|
2007-01-27 17:37:36 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2007-01-28 04:25:58 +00:00
|
|
|
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.
|
2007-01-27 17:37:36 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<function>mysqli_fetch_array</function> is an extended version of the
|
2007-01-28 04:25:58 +00:00
|
|
|
<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.
|
2007-01-27 17:37:36 +00:00
|
|
|
</para>
|
|
|
|
&database.field-case;
|
|
|
|
&database.fetch-null;
|
|
|
|
<para>
|
2007-01-28 04:25:58 +00:00
|
|
|
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.
|
2007-01-27 17:37:36 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-01-28 04:25:58 +00:00
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2007-01-27 17:37:36 +00:00
|
|
|
<para>
|
2007-01-28 04:25:58 +00:00
|
|
|
<variablelist>
|
|
|
|
&mysqli.result.description;
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>resulttype</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This optional 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 <constant>MYSQLI_ASSOC</constant>,
|
|
|
|
<constant>MYSQLI_NUM</constant>, or <constant>MYSQLI_BOTH</constant>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
By using the <constant>MYSQLI_ASSOC</constant> constant this function
|
|
|
|
will behave identically to the <function>mysqli_fetch_assoc</function>,
|
|
|
|
while <constant>MYSQLI_NUM</constant> will behave identically to the
|
|
|
|
<function>mysqli_fetch_row</function> function. The final option
|
|
|
|
<constant>MYSQLI_BOTH</constant> will create a single array with the
|
|
|
|
attributes of both.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2007-01-27 17:37:36 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-01-28 04:25:58 +00:00
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2007-01-27 17:37:36 +00:00
|
|
|
<para>
|
2007-03-25 18:08:03 +00:00
|
|
|
Returns an array of strings that corresponds to the fetched row or &null; if there
|
2007-01-28 04:25:58 +00:00
|
|
|
are no more rows in resultset.
|
2007-01-27 17:37:36 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-01-28 04:25:58 +00:00
|
|
|
|
|
|
|
<refsect1 role="examples">
|
2007-01-27 17:37:36 +00:00
|
|
|
&reftitle.examples;
|
|
|
|
<example>
|
2011-12-29 05:36:04 +00:00
|
|
|
<title>&style.oop;</title>
|
2007-01-27 17:37:36 +00:00
|
|
|
<programlisting role="php">
|
2003-05-13 23:12:16 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2004-02-25 21:59:16 +00:00
|
|
|
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* check connection */
|
|
|
|
if (mysqli_connect_errno()) {
|
|
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
2007-01-27 17:37:36 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
|
|
|
|
$result = $mysqli->query($query);
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
/* numeric array */
|
2004-02-25 21:59:16 +00:00
|
|
|
$row = $result->fetch_array(MYSQLI_NUM);
|
2007-01-27 17:37:36 +00:00
|
|
|
printf ("%s (%s)\n", $row[0], $row[1]);
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
/* associative array */
|
2004-02-25 21:59:16 +00:00
|
|
|
$row = $result->fetch_array(MYSQLI_ASSOC);
|
2007-01-27 17:37:36 +00:00
|
|
|
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
/* associative and numeric array */
|
2004-02-25 21:59:16 +00:00
|
|
|
$row = $result->fetch_array(MYSQLI_BOTH);
|
2007-01-27 17:37:36 +00:00
|
|
|
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
|
2004-02-25 21:59:16 +00:00
|
|
|
|
|
|
|
/* free result set */
|
2012-04-07 19:18:51 +00:00
|
|
|
$result->free();
|
2004-02-21 08:44:40 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* close connection */
|
2004-02-21 08:44:40 +00:00
|
|
|
$mysqli->close();
|
2003-05-13 23:12:16 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2010-05-08 23:37:27 +00:00
|
|
|
</programlisting>
|
2011-12-29 05:36:04 +00:00
|
|
|
</example>
|
|
|
|
<example>
|
|
|
|
<title>&style.procedural;</title>
|
2007-01-27 17:37:36 +00:00
|
|
|
<programlisting role="php">
|
2003-05-13 23:12:16 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2004-02-25 21:59:16 +00:00
|
|
|
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
|
2004-02-21 08:44:40 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* check connection */
|
|
|
|
if (mysqli_connect_errno()) {
|
|
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
|
|
|
|
$result = mysqli_query($link, $query);
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
/* numeric array */
|
2004-02-25 21:59:16 +00:00
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_NUM);
|
2007-01-27 17:37:36 +00:00
|
|
|
printf ("%s (%s)\n", $row[0], $row[1]);
|
2004-02-21 08:44:40 +00:00
|
|
|
|
|
|
|
/* associative array */
|
2004-02-25 21:59:16 +00:00
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
2007-01-27 17:37:36 +00:00
|
|
|
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
|
2004-02-21 08:44:40 +00:00
|
|
|
|
|
|
|
/* associative and numeric array */
|
2004-02-25 21:59:16 +00:00
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
|
2007-01-27 17:37:36 +00:00
|
|
|
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
|
2004-02-25 21:59:16 +00:00
|
|
|
|
|
|
|
/* free result set */
|
2004-02-21 08:44:40 +00:00
|
|
|
mysqli_free_result($result);
|
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* close connection */
|
2004-02-21 08:44:40 +00:00
|
|
|
mysqli_close($link);
|
2003-05-13 23:12:16 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2007-01-27 17:37:36 +00:00
|
|
|
</programlisting>
|
2010-05-08 23:37:27 +00:00
|
|
|
&examples.outputs;
|
|
|
|
<screen>
|
2004-02-25 21:59:16 +00:00
|
|
|
<![CDATA[
|
|
|
|
Kabul (AFG)
|
|
|
|
Qandahar (AFG)
|
|
|
|
Herat (AFG)
|
|
|
|
]]>
|
2010-05-08 23:37:27 +00:00
|
|
|
</screen>
|
|
|
|
</example>
|
2007-01-27 17:37:36 +00:00
|
|
|
</refsect1>
|
2007-01-28 04:25:58 +00:00
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
<simplelist>
|
|
|
|
<member><function>mysqli_fetch_assoc</function></member>
|
|
|
|
<member><function>mysqli_fetch_row</function></member>
|
|
|
|
<member><function>mysqli_fetch_object</function></member>
|
|
|
|
<member><function>mysqli_query</function></member>
|
|
|
|
<member><function>mysqli_data_seek</function></member>
|
|
|
|
</simplelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2007-01-27 17:37:36 +00:00
|
|
|
</refentry>
|
2003-03-15 23:01:35 +00:00
|
|
|
|
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2003-03-15 23:01:35 +00:00
|
|
|
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
|
|
|
|
-->
|