Files
php-doc-ru/reference/mysql/functions/mysql-fetch-array.xml
Shein Alexey b949d4e80d Fixed markup error.
git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@311750 c90b9560-bf6c-de11-be94-00142212c4b1
2011-06-03 07:26:10 +00:00

196 lines
6.7 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 96c9d88bad9a7d7d44bfb7f26c226df7ee9ddf26 Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<!-- $Revision$ -->
<refentry xml:id="function.mysql-fetch-array" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysql_fetch_array</refname>
<refpurpose>Обрабатывает ряд результата запроса, возвращая ассоциативный массив, численный массив или оба</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>mysql_fetch_array</methodname>
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>result_type</parameter><initializer>MYSQL_BOTH</initializer></methodparam>
</methodsynopsis>
<para>
Возвращает массив, соответствующий обработанному ряду результата
запроса и сдвигает внутренний указатель данных вперед.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
&mysql.result.description;
<varlistentry>
<term><parameter>result_type</parameter></term>
<listitem>
<para>
Тип возвращаемого массива. Является константой и может принимать
следующие значения: <constant>MYSQL_ASSOC</constant>,
<constant>MYSQL_NUM</constant> и
<constant>MYSQL_BOTH</constant>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает массив строк, соответствующих обработанному ряду результата
запроса, или &false;, если рядов больше нет. Тип возвращаемого
массива зависит от значения параметра <parameter>result_type</parameter>.
При использовании <constant>MYSQL_BOTH</constant> (по умолчанию),
вы получите массив, состоящий как из ассоциативных индексов,
так и из численных. <constant>MYSQL_ASSOC</constant> вернёт
только ассоциативные индексы (аналогично функции
<function>mysql_fetch_assoc</function>), а
<constant>MYSQL_NUM</constant> - только численные (аналогично
функции <function>mysql_fetch_row</function>).
</para>
<para>
Если несколько колонок в результате будут иметь одинаковые
названия, то будет возвращена последняя колонка. Чтобы получить
доступ к другим колонкам с тем же именем, используйте численные
индексы массива или псевдонимы в запросе. В случае псевдонимов
используйте именно их - вы не сможете использовать настоящие
имена колонок.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Запрос с применением псевдонимов для дублирующихся имен колонок</title>
<programlisting role="sql">
<![CDATA[
SELECT table1.field AS foo, table2.field AS bar FROM table1, table2
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>mysql_fetch_array</function> с <constant>MYSQL_NUM</constant></title>
<programlisting role="php">
<![CDATA[
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Ошибка соединения: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Имя: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>mysql_fetch_array</function> с <constant>MYSQL_ASSOC</constant></title>
<programlisting role="php">
<![CDATA[
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Ошибка соединения: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("ID: %s Имя: %s", $row["id"], $row["name"]);
}
mysql_free_result($result);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>mysql_fetch_array</function> с <constant>MYSQL_BOTH</constant></title>
<programlisting role="php">
<![CDATA[
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Ошибка соединения: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("ID: %s Имя: %s", $row[0], $row["name"]);
}
mysql_free_result($result);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<title>Производительность</title>
<para>
Важно заметить, что <function>mysql_fetch_array</function>
работает <emphasis>незначительно</emphasis> медленнее,
чем <function>mysql_fetch_row</function>, в то же время
предоставляя намного более удобный доступ к данным.
</para>
</note>
&database.field-case;
&database.fetch-null;
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>mysql_fetch_row</function></member>
<member><function>mysql_fetch_assoc</function></member>
<member><function>mysql_data_seek</function></member>
<member><function>mysql_query</function></member>
</simplelist>
</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:"~/.phpdoc/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
-->