2003-03-15 23:01:35 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-02-21 08:44:40 +00:00
|
|
|
<!-- $Revision: 1.8 $ -->
|
2003-03-15 23:01:35 +00:00
|
|
|
<refentry id="function.mysqli-fetch-assoc">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>mysqli_fetch_assoc</refname>
|
2004-01-28 23:18:42 +00:00
|
|
|
<refname>mysqli->fetch_assoc</refname>
|
2003-05-13 23:12:16 +00:00
|
|
|
<refpurpose>Fetch a result row as an associative array</refpurpose>
|
2003-03-15 23:01:35 +00:00
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
2004-01-28 23:18:42 +00:00
|
|
|
<para>Procedural style:</para>
|
2003-03-15 23:01:35 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>array</type><methodname>mysqli_fetch_assoc</methodname>
|
2004-01-28 23:18:42 +00:00
|
|
|
<methodparam><type>object</type><parameter>result</parameter></methodparam>
|
2003-03-15 23:01:35 +00:00
|
|
|
</methodsynopsis>
|
2004-01-28 23:18:42 +00:00
|
|
|
<para>Object oriend style (method):</para>
|
|
|
|
<classsynopsis>
|
|
|
|
<ooclass><classname>result</classname></ooclass>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>array</type>
|
|
|
|
<methodname>fetch_assoc</methodname>
|
|
|
|
<methodparam><type>void</type><parameter></parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
</classsynopsis>
|
2003-03-15 23:01:35 +00:00
|
|
|
<para>
|
2004-02-21 08:44:40 +00:00
|
|
|
Returns an associative array that corresponds to the fetched row or &null; if there are
|
2003-06-11 08:10:35 +00:00
|
|
|
no more rows.
|
2003-03-15 23:01:35 +00:00
|
|
|
</para>
|
2003-05-13 23:12:16 +00:00
|
|
|
<para>
|
2003-05-25 19:09:28 +00:00
|
|
|
The <function>mysqli_fetch_assoc</function> function is used to return an associative array
|
|
|
|
representing the next row in the result set for the result represented by the
|
|
|
|
<parameter>result</parameter> parameter, where each key in the array represents the name
|
|
|
|
of one of the result set's columns.
|
2003-05-13 23:12:16 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2003-05-25 19:09:28 +00:00
|
|
|
If two or more columns in the result set have the same column name, the associative array
|
|
|
|
returned by the <function>mysqli_fetch_assoc</function> function will contain the value of
|
2004-01-28 23:18:42 +00:00
|
|
|
the last column of that name. If you must work with result sets with this properity, the
|
2003-05-25 19:09:28 +00:00
|
|
|
<function>mysqli_fetch_row</function> should be used which returns an numerically-indexed
|
|
|
|
array instead.
|
2003-05-13 23:12:16 +00:00
|
|
|
</para>
|
2003-07-03 08:26:08 +00:00
|
|
|
&database.field-case;
|
2004-01-28 23:18:42 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1>
|
|
|
|
<title>Return values</title>
|
|
|
|
<para>
|
2004-02-21 08:44:40 +00:00
|
|
|
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>mysqli_fetch_array</function>,
|
|
|
|
<function>mysqli_fetch_row</function>,
|
|
|
|
<function>mysqli_fetch_object</function>.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1>
|
|
|
|
<title>Example</title>
|
2003-05-13 23:12:16 +00:00
|
|
|
<example>
|
2004-02-21 08:44:40 +00:00
|
|
|
<title>Object oriented style</title>
|
2003-05-13 23:12:16 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2004-02-21 08:44:40 +00:00
|
|
|
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
$mysqli->query( "DROP TABLE IF EXISTS friends");
|
|
|
|
$mysqli->query( "CREATE TABLE friends (id int, name varchar(20))");
|
|
|
|
|
|
|
|
$mysqli->query( "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')");
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
$result = $mysqli->query( "SELECT id, name FROM friends");
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
printf ("ID: %s Name: %s\n", $row["id"], $row["name"]);
|
|
|
|
}
|
|
|
|
$result->close();
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
$mysqli->close();
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
<example>
|
|
|
|
<title>Procedural style</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
|
|
|
|
|
|
|
|
mysqli_query($link, "DROP TABLE IF EXISTS friends");
|
|
|
|
mysqli_query($link, "CREATE TABLE friends (id int, name varchar(20))");
|
|
|
|
|
|
|
|
mysqli_query($link, "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')");
|
|
|
|
|
|
|
|
$result = mysqli_query($link, "SELECT id, name FROM friends");
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
printf ("ID: %s Name: %s\n", $row["id"], $row["name"]);
|
2003-05-13 23:12:16 +00:00
|
|
|
}
|
2004-02-21 08:44:40 +00:00
|
|
|
mysqli_free_result($result);
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-21 08:44:40 +00:00
|
|
|
mysqli_close($link);
|
2003-05-13 23:12:16 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2004-01-28 23:18:42 +00:00
|
|
|
</refsect1>
|
2003-03-15 23:01:35 +00:00
|
|
|
</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
|
|
|
|
-->
|