-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathmysql-fetch-array.xml
119 lines (114 loc) · 3.7 KB
/
mysql-fetch-array.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 4754397753fd79f1c846868b66a2448babab1c54 Maintainer: HonestQiao Status: ready -->
<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></methodparam>
</methodsynopsis>
<para>
<function>mysql_fetch_array</function> 是
<function>mysql_fetch_row</function>
的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。
</para>
<para>
有一点很重要必须指出,用
<function>mysql_fetch_array</function> 并<emphasis>不明显</emphasis> 比用
<function>mysql_fetch_row</function> 慢,而且还提供了明显更多的值。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
&mysql.result.description;
<varlistentry>
<term><parameter>result_type</parameter></term>
<listitem>
<para>
接受以下常量值:
<constant>MSQL_ASSOC</constant>,<constant>MSQL_NUM</constant> 和
<constant>MSQL_BOTH</constant>,默认为 <constant>MSQL_BOTH</constant>。如果用了
MYSQL_BOTH,将得到一个同时包含关联和数字索引的数组。用
MYSQL_ASSOC 只得到关联索引(如同 <function>mysql_fetch_assoc</function> 那样),用
MYSQL_NUM 只得到数字索引(如同 <function>mysql_fetch_row</function> 那样)。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 &false;。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>msql_fetch_array</function> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
$con = msql_connect();
if (!$con) {
die('Server connection problem: ' . msql_error());
}
if (!msql_select_db('test', $con)) {
die('Database connection problem: ' . msql_error());
}
$result = msql_query('SELECT id, name FROM people', $con);
if (!$result) {
die('Query execution problem: ' . msql_error());
}
while ($row = msql_fetch_array($result, MSQL_ASSOC)) {
echo $row['id'] . ': ' . $row['name'] . "\n";
}
msql_free_result($result);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>msql_fetch_row</function></member>
<member><function>msql_fetch_object</function></member>
<member><function>msql_data_seek</function></member>
<member><function>msql_result</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
-->