reference/mysqli/mysqli_result/fetch-all.xml
035c126c0393fe154bac46e2c3c489ebadce48a5
...
...
@@ -4,26 +4,32 @@
4
4
<refnamediv>
5
5
<refname>mysqli_result::fetch_all</refname>
6
6
<refname>mysqli_fetch_all</refname>
7
-
<refpurpose>Fetches all result rows as an associative array, a numeric array, or both</refpurpose>
7
+
<refpurpose>Fetch all result rows as an associative array, 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_all</methodname>
15
-
<methodparam choice="opt"><type>int</type><parameter>resulttype</parameter><initializer>MYSQLI_NUM</initializer></methodparam>
13
+
<methodsynopsis role="mysqli_result">
14
+
<modifier>public</modifier> <type>array</type><methodname>mysqli_result::fetch_all</methodname>
15
+
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>MYSQLI_NUM</constant></initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
18
18
<methodsynopsis>
19
-
<type>mixed</type><methodname>mysqli_fetch_all</methodname>
19
+
<type>array</type><methodname>mysqli_fetch_all</methodname>
20
20
<methodparam><type>mysqli_result</type><parameter>result</parameter></methodparam>
21
-
<methodparam choice="opt"><type>int</type><parameter>resulttype</parameter><initializer>MYSQLI_NUM</initializer></methodparam>
21
+
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>MYSQLI_NUM</constant></initializer></methodparam>
22
22
</methodsynopsis>
23
23
<para>
24
-
<function>mysqli_fetch_all</function> fetches all result rows and returns the result
25
-
set as an associative array, a numeric array, or both.
24
+
Returns a two-dimensional array of all result rows
25
+
as an associative array, a numeric array, or both.
26
26
</para>
27
+
<note>
28
+
<para>
29
+
Prior to PHP 8.1.0, available only with
30
+
<link xmlns="http://docbook.org/ns/docbook" linkend="book.mysqlnd">mysqlnd</link>.
31
+
</para>
32
+
</note>
27
33
</refsect1>
28
34

29
35
<refsect1 role="parameters">
...
...
@@ -32,7 +38,7 @@
32
38
<variablelist>
33
39
&mysqli.result.description;
34
40
<varlistentry>
35
-
<term><parameter>resulttype</parameter></term>
41
+
<term><parameter>mode</parameter></term>
36
42
<listitem>
37
43
<para>
38
44
This optional parameter is a constant indicating what type of array
...
...
@@ -53,24 +59,73 @@
53
59
</para>
54
60
</refsect1>
55
61

56
-
<refsect1 role="mysqlnd">
57
-
&reftitle.mysqlnd;
62
+
<refsect1 role="changelog">
63
+
&reftitle.changelog;
64
+
<informaltable>
65
+
<tgroup cols="2">
66
+
<thead>
67
+
<row>
68
+
<entry>&Version;</entry>
69
+
<entry>&Description;</entry>
70
+
</row>
71
+
</thead>
72
+
<tbody>
73
+
<row>
74
+
<entry>8.1.0</entry>
75
+
<entry>
76
+
Now also available when linking against libmysqlclient.
77
+
</entry>
78
+
</row>
79
+
</tbody>
80
+
</tgroup>
81
+
</informaltable>
82
+
</refsect1>
58
83

59
-
<para>
60
-
&mysqli.available.mysqlnd;
61
-
</para>
84
+
<refsect1 role="examples">
85
+
&reftitle.examples;
86
+
<example>
87
+
<title><methodname>mysqli_result::fetch_all</methodname> example</title>
88
+
<para>&style.oop;</para>
89
+
<programlisting role="php">
90
+
<![CDATA[
91
+
<?php
62
92

63
-
<para>
64
-
As <function>mysqli_fetch_all</function> returns all the rows as an
65
-
array in a single step, it may consume more memory than some similar
66
-
functions such as <function>mysqli_fetch_array</function>, which
67
-
only returns one row at a time from the result set. Further, if you
68
-
need to iterate over the result set, you will need a looping
69
-
construct that will further impact performance. For these reasons
70
-
<function>mysqli_fetch_all</function> should only be used in those
71
-
situations where the fetched result set will be sent to another
72
-
layer for processing.
73
-
</para>
93
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
94
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
95
+

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

98
+
$rows = $result->fetch_all(MYSQLI_ASSOC);
99
+
foreach ($rows as $row) {
100
+
printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
101
+
}
102
+
]]>
103
+
</programlisting>
104
+
<para>&style.procedural;</para>
105
+
<programlisting role="php">
106
+
<![CDATA[
107
+
<?php
108
+

109
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
110
+
$mysqli = mysqli_connect("localhost", "my_user", "my_password", "world");
111
+

112
+
$result = mysqli_query($mysqli, "SELECT Name, CountryCode FROM City ORDER BY ID LIMIT 3");
113
+

114
+
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
115
+
foreach ($rows as $row) {
116
+
printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
117
+
}
118
+
]]>
119
+
</programlisting>
120
+
&examples.outputs;
121
+
<screen>
122
+
<![CDATA[
123
+
Kabul (AFG)
124
+
Qandahar (AFG)
125
+
Herat (AFG)
126
+
]]>
127
+
</screen>
128
+
</example>
74
129
</refsect1>
75
130

76
131
<refsect1 role="seealso">
...
...
@@ -78,13 +133,13 @@
78
133
<para>
79
134
<simplelist>
80
135
<member><function>mysqli_fetch_array</function></member>
136
+
<member><function>mysqli_fetch_column</function></member>
81
137
<member><function>mysqli_query</function></member>
82
138
</simplelist>
83
139
</para>
84
140
</refsect1>
85
141

86
142
</refentry>
87
-

88
143
<!-- Keep this comment at the end of the file
89
144
Local variables:
90
145
mode: sgml
91
146