reference/mysqli/mysqli_result/fetch-array.xml
035c126c0393fe154bac46e2c3c489ebadce48a5
...
...
@@ -4,42 +4,40 @@
4
4
<refnamediv>
5
5
<refname>mysqli_result::fetch_array</refname>
6
6
<refname>mysqli_fetch_array</refname>
7
-
<refpurpose>Fetch a result row as an associative, a numeric array, or both</refpurpose>
7
+
<refpurpose>Fetch the next row of a result set as an associative, a numeric array, or both</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
14
-
<type>mixed</type><methodname>mysqli_result::fetch_array</methodname>
15
-
<methodparam choice="opt"><type>int</type><parameter>resulttype</parameter><initializer>MYSQLI_BOTH</initializer></methodparam>
13
+
<methodsynopsis role="mysqli_result">
14
+
<modifier>public</modifier> <type class="union"><type>array</type><type>null</type><type>false</type></type><methodname>mysqli_result::fetch_array</methodname>
15
+
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>MYSQLI_BOTH</constant></initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
18
18
<methodsynopsis>
19
-
<type>mixed</type><methodname>mysqli_fetch_array</methodname>
19
+
<type class="union"><type>array</type><type>null</type><type>false</type></type><methodname>mysqli_fetch_array</methodname>
20
20
<methodparam><type>mysqli_result</type><parameter>result</parameter></methodparam>
21
-
<methodparam choice="opt"><type>int</type><parameter>resulttype</parameter><initializer>MYSQLI_BOTH</initializer></methodparam>
21
+
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>MYSQLI_BOTH</constant></initializer></methodparam>
22
22
</methodsynopsis>
23
23
<para>
24
-
Returns an array that corresponds to the fetched row or &null; if there
25
-
are no more rows for the resultset represented by the
26
-
<parameter>result</parameter> parameter.
24
+
Fetches one row of data from the result set and returns it as an array.
25
+
Each subsequent call to this function will return the next row within the
26
+
result set, or &null; if there are no more rows.
27
27
</para>
28
28
<para>
29
-
<function>mysqli_fetch_array</function> is an extended version of the
30
-
<function>mysqli_fetch_row</function> function. In addition to storing the
31
-
data in the numeric indices of the result array, the
32
-
<function>mysqli_fetch_array</function> function can also store the data
33
-
in associative indices, using the field names of the result set as keys.
29
+
In addition to storing the data in the numeric indices of the result array,
30
+
this function can also store the data in associative indices
31
+
by using the field names of the result set as keys.
34
32
</para>
35
-
&database.field-case;
36
-
&database.fetch-null;
37
33
<para>
38
-
If two or more columns of the result have the same field names, the last
39
-
column will take precedence and overwrite the earlier data. In order to
34
+
If two or more columns of the result have the same name, the last
35
+
column will take precedence and overwrite any previous data. To
40
36
access multiple columns with the same name, the numerically indexed
41
37
version of the row must be used.
42
38
</para>
39
+
&database.field-case;
40
+
&database.fetch-null;
43
41
</refsect1>
44
42

45
43
<refsect1 role="parameters">
...
...
@@ -48,7 +46,7 @@
48
46
<variablelist>
49
47
&mysqli.result.description;
50
48
<varlistentry>
51
-
<term><parameter>resulttype</parameter></term>
49
+
<term><parameter>mode</parameter></term>
52
50
<listitem>
53
51
<para>
54
52
This optional parameter is a constant indicating what type of array
...
...
@@ -73,87 +71,64 @@
73
71
<refsect1 role="returnvalues">
74
72
&reftitle.returnvalues;
75
73
<para>
76
-
Returns an array of strings that corresponds to the fetched row or &null; if there
77
-
are no more rows in resultset.
74
+
Returns an array representing the fetched row, &null; if there
75
+
are no more rows in the result set, &return.falseforfailure;.
78
76
</para>
79
77
</refsect1>
80
78

81
79
<refsect1 role="examples">
82
80
&reftitle.examples;
83
81
<example>
84
-
<title>&style.oop;</title>
82
+
<title><methodname>mysqli_result::fetch_array</methodname> example</title>
83
+
<para>&style.oop;</para>
85
84
<programlisting role="php">
86
85
<![CDATA[
87
86
<?php
88
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
89
87

90
-
/* check connection */
91
-
if ($mysqli->connect_errno) {
92
-
printf("Connect failed: %s\n", $mysqli->connect_error);
93
-
exit();
94
-
}
88
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
89
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
95
90

96
-
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
91
+
$query = "SELECT Name, CountryCode FROM City ORDER BY ID LIMIT 3";
97
92
$result = $mysqli->query($query);
98
93

99
94
/* numeric array */
100
95
$row = $result->fetch_array(MYSQLI_NUM);
101
-
printf ("%s (%s)\n", $row[0], $row[1]);
96
+
printf("%s (%s)\n", $row[0], $row[1]);
102
97

103
98
/* associative array */
104
99
$row = $result->fetch_array(MYSQLI_ASSOC);
105
-
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
100
+
printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
106
101

107
102
/* associative and numeric array */
108
103
$row = $result->fetch_array(MYSQLI_BOTH);
109
-
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
110
-

111
-
/* free result set */
112
-
$result->free();
113
-

114
-
/* close connection */
115
-
$mysqli->close();
116
-
?>
104
+
printf("%s (%s)\n", $row[0], $row["CountryCode"]);
117
105
]]>
118
106
</programlisting>
119
-
</example>
120
-
<example>
121
-
<title>&style.procedural;</title>
107
+
<para>&style.procedural;</para>
122
108
<programlisting role="php">
123
109
<![CDATA[
124
110
<?php
125
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
126
111

127
-
/* check connection */
128
-
if (mysqli_connect_errno()) {
129
-
printf("Connect failed: %s\n", mysqli_connect_error());
130
-
exit();
131
-
}
112
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
113
+
$mysqli = mysqli_connect("localhost", "my_user", "my_password", "world");
132
114

133
115
$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
134
-
$result = mysqli_query($link, $query);
116
+
$result = mysqli_query($mysqli, $query);
135
117

136
118
/* numeric array */
137
119
$row = mysqli_fetch_array($result, MYSQLI_NUM);
138
-
printf ("%s (%s)\n", $row[0], $row[1]);
120
+
printf("%s (%s)\n", $row[0], $row[1]);
139
121

140
122
/* associative array */
141
123
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
142
-
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
124
+
printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
143
125

144
126
/* associative and numeric array */
145
127
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
146
-
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
147
-

148
-
/* free result set */
149
-
mysqli_free_result($result);
150
-

151
-
/* close connection */
152
-
mysqli_close($link);
153
-
?>
128
+
printf("%s (%s)\n", $row[0], $row["CountryCode"]);
154
129
]]>
155
130
</programlisting>
156
-
&examples.outputs;
131
+
&examples.outputs.similar;
157
132
<screen>
158
133
<![CDATA[
159
134
Kabul (AFG)
...
...
@@ -169,6 +144,7 @@ Herat (AFG)
169
144
<para>
170
145
<simplelist>
171
146
<member><function>mysqli_fetch_assoc</function></member>
147
+
<member><function>mysqli_fetch_column</function></member>
172
148
<member><function>mysqli_fetch_row</function></member>
173
149
<member><function>mysqli_fetch_object</function></member>
174
150
<member><function>mysqli_query</function></member>
...
...
@@ -178,7 +154,6 @@ Herat (AFG)
178
154
</refsect1>
179
155

180
156
</refentry>
181
-

182
157
<!-- Keep this comment at the end of the file
183
158
Local variables:
184
159
mode: sgml
185
160