2003-03-15 23:01:35 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-03-16 15:26:37 +00:00
|
|
|
<!-- $Revision: 1.11 $ -->
|
|
|
|
<!-- EN-Revision: 1.10 Maintainer: baoengb Status: ready -->
|
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>
|
2004-03-16 15:26:37 +00:00
|
|
|
<refpurpose>Obtiene una fila del resultado como una matriz asociativa</refpurpose>
|
2003-03-15 23:01:35 +00:00
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Descripción</title>
|
|
|
|
<para>Estilo por procedimientos:</para>
|
2003-03-15 23:01:35 +00:00
|
|
|
<methodsynopsis>
|
2004-03-16 15:26:37 +00:00
|
|
|
<type>matriz</type><methodname>mysqli_fetch_assoc</methodname>
|
|
|
|
<methodparam><type>objeto</type><parameter>resultado</parameter></methodparam>
|
2003-03-15 23:01:35 +00:00
|
|
|
</methodsynopsis>
|
2004-03-16 15:26:37 +00:00
|
|
|
<para>Estilo orientado a objetos (método):</para>
|
2004-01-28 23:18:42 +00:00
|
|
|
<classsynopsis>
|
2004-03-16 15:26:37 +00:00
|
|
|
<ooclass><classname>resultado</classname></ooclass>
|
2004-01-28 23:18:42 +00:00
|
|
|
<methodsynopsis>
|
2004-03-16 15:26:37 +00:00
|
|
|
<type>matriz</type>
|
2004-01-28 23:18:42 +00:00
|
|
|
<methodname>fetch_assoc</methodname>
|
|
|
|
<methodparam><type>void</type><parameter></parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
</classsynopsis>
|
2003-03-15 23:01:35 +00:00
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Regresa una matriz asociativa que corresponde a las filas obtenidas o &null;
|
|
|
|
si no hay mas filas.
|
2003-03-15 23:01:35 +00:00
|
|
|
</para>
|
2003-05-13 23:12:16 +00:00
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
La función <function>mysqli_fetch_assoc</function> es usada para regresar
|
|
|
|
una representación asociativa de la siguiente fila en el resultado,
|
|
|
|
representado por el parámetro <parameter>resultado</parameter>, donde
|
|
|
|
cada llave en la matriz representa el nombre de las columnas en el resultado.
|
2003-05-13 23:12:16 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Si dos o más columnas de el resultado tienen el mismo nombre, la última
|
|
|
|
columna tomara precedencia y sobre escribirá lo primero. Para acceder a
|
|
|
|
varias columnas con el mismo nombre, la forma de índice numérica
|
|
|
|
debe ser usada.
|
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>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Valores regresados</title>
|
2004-01-28 23:18:42 +00:00
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Regresa una matriz que corresponde a las filas obtenidas o &null; si no hay
|
|
|
|
más filas en el resultado.
|
2004-02-21 08:44:40 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Vea también</title>
|
2004-02-21 08:44:40 +00:00
|
|
|
<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>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Ejemplos</title>
|
2003-05-13 23:12:16 +00:00
|
|
|
<example>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Estilo orientado a objetos</title>
|
2003-05-13 23:12:16 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![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();
|
|
|
|
}
|
2004-02-21 08:44:40 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
|
|
|
|
|
|
|
|
if ($result = $mysqli->query($query)) {
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* fetch associative array */
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
|
|
|
|
}
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* free result set */
|
|
|
|
$result->close();
|
2004-02-21 08:44:40 +00:00
|
|
|
}
|
2003-05-13 23:12:16 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* close connection */
|
2004-02-21 08:44:40 +00:00
|
|
|
$mysqli->close();
|
|
|
|
?>
|
|
|
|
]]>
|
2004-02-25 21:59:16 +00:00
|
|
|
</programlisting>
|
2004-02-21 08:44:40 +00:00
|
|
|
</example>
|
|
|
|
<example>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Estilo por procedimientos</title>
|
2004-02-21 08:44:40 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
|
2004-02-21 08:44:40 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
if ($result = mysqli_query($link, $query)) {
|
2004-02-21 08:44:40 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* fetch associative array */
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
|
2003-05-13 23:12:16 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* free result set */
|
|
|
|
mysqli_free_result($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close connection */
|
2004-02-21 08:44:40 +00:00
|
|
|
mysqli_close($link);
|
2003-05-13 23:12:16 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2004-02-25 21:59:16 +00:00
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Los ejemplos anteriores producirán la siguiente salida:
|
2004-02-25 21:59:16 +00:00
|
|
|
</para>
|
|
|
|
<screen>
|
|
|
|
<![CDATA[
|
|
|
|
Pueblo (USA)
|
|
|
|
Arvada (USA)
|
|
|
|
Cape Coral (USA)
|
|
|
|
Green Bay (USA)
|
|
|
|
Santa Clara (USA)
|
|
|
|
]]>
|
|
|
|
</screen>
|
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
|
|
|
|
-->
|