reference/pdo/pdostatement/fetchall.xml
28529d3539b850e870e3aa97570f4db0e53daa03
...
...
@@ -4,18 +4,34 @@
4
4
<refnamediv>
5
5
<refname>PDOStatement::fetchAll</refname>
6
6
<refpurpose>
7
-
Returns an array containing all of the result set rows
7
+
Fetches the remaining rows from a result set
8
8
</refpurpose>
9
9
</refnamediv>
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<methodsynopsis>
12
+
<methodsynopsis role="PDOStatement">
13
13
<modifier>public</modifier> <type>array</type><methodname>PDOStatement::fetchAll</methodname>
14
-
<methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam>
15
-
<methodparam choice="opt"><type>mixed</type><parameter>fetch_argument</parameter></methodparam>
16
-
<methodparam choice="opt"><type>array</type><parameter>ctor_args</parameter><initializer>array()</initializer></methodparam>
14
+
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer>PDO::FETCH_DEFAULT</initializer></methodparam>
17
15
</methodsynopsis>
18
16

17
+
<methodsynopsis role="PDOStatement">
18
+
<modifier>public</modifier> <type>array</type><methodname>PDOStatement::fetchAll</methodname>
19
+
<methodparam><type>int</type><parameter>mode</parameter><initializer>PDO::FETCH_COLUMN</initializer></methodparam>
20
+
<methodparam><type>int</type><parameter>column</parameter></methodparam>
21
+
</methodsynopsis>
22
+

23
+
<methodsynopsis role="PDOStatement">
24
+
<modifier>public</modifier> <type>array</type><methodname>PDOStatement::fetchAll</methodname>
25
+
<methodparam><type>int</type><parameter>mode</parameter><initializer>PDO::FETCH_CLASS</initializer></methodparam>
26
+
<methodparam><type>string</type><parameter>class</parameter></methodparam>
27
+
<methodparam><type class="union"><type>array</type><type>null</type></type><parameter>constructorArgs</parameter></methodparam>
28
+
</methodsynopsis>
29
+

30
+
<methodsynopsis role="PDOStatement">
31
+
<modifier>public</modifier> <type>array</type><methodname>PDOStatement::fetchAll</methodname>
32
+
<methodparam><type>int</type><parameter>mode</parameter><initializer>PDO::FETCH_FUNC</initializer></methodparam>
33
+
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
34
+
</methodsynopsis>
19
35
</refsect1>
20
36

21
37
<refsect1 role="parameters">
...
...
@@ -23,11 +39,11 @@
23
39
<para>
24
40
<variablelist>
25
41
<varlistentry>
26
-
<term><parameter>fetch_style</parameter></term>
42
+
<term><parameter>mode</parameter></term>
27
43
<listitem>
28
44
<para>
29
45
Controls the contents of the returned array as documented in
30
-
<function>PDOStatement::fetch</function>.
46
+
<methodname>PDOStatement::fetch</methodname>.
31
47
Defaults to value of <constant>PDO::ATTR_DEFAULT_FETCH_MODE</constant>
32
48
(which defaults to <constant>PDO::FETCH_BOTH</constant>)
33
49
</para>
...
...
@@ -35,7 +51,7 @@
35
51
To return an array consisting of all values of a single column from
36
52
the result set, specify <constant>PDO::FETCH_COLUMN</constant>. You
37
53
can specify which column you want with the
38
-
<parameter>fetch_argument</parameter> parameter.
54
+
<parameter>column</parameter> parameter.
39
55
</para>
40
56
<para>
41
57
To fetch only the unique values of a single column from the result set,
...
...
@@ -49,44 +65,46 @@
49
65
</para>
50
66
</listitem>
51
67
</varlistentry>
68
+
</variablelist>
69
+
The following are dynamic parameters that are depending on the fetch mode.
70
+
They can't be used with named parameters.
71
+
<variablelist>
72
+
<varlistentry>
73
+
<term><parameter>column</parameter></term>
74
+
<listitem>
75
+
<para>
76
+
Used with <constant>PDO::FETCH_COLUMN</constant>. Returns the indicated
77
+
0-indexed column.
78
+
</para>
79
+
</listitem>
80
+
</varlistentry>
52
81
<varlistentry>
53
-
<term><parameter>fetch_argument</parameter></term>
82
+
<term><parameter>class</parameter></term>
54
83
<listitem>
55
84
<para>
56
-
This argument has a different meaning depending on the value of
57
-
the <parameter>fetch_style</parameter> parameter:
58
-
<itemizedlist>
59
-
<listitem>
60
-
<para>
61
-
<constant>PDO::FETCH_COLUMN</constant>: Returns the indicated 0-indexed
62
-
column.
63
-
</para>
64
-
</listitem>
65
-
<listitem>
66
-
<para>
67
-
<constant>PDO::FETCH_CLASS</constant>: Returns instances of the specified
68
-
class, mapping the columns of each row to named properties in the class.
69
-
</para>
70
-
</listitem>
71
-
<listitem>
72
-
<para>
73
-
<constant>PDO::FETCH_FUNC</constant>: Returns the results of calling the
74
-
specified function, using each row's columns as parameters in the call.
75
-
</para>
76
-
</listitem>
77
-
</itemizedlist>
85
+
Used with <constant>PDO::FETCH_CLASS</constant>. Returns instances of the specified
86
+
class, mapping the columns of each row to named properties in the class.
78
87
</para>
79
88
</listitem>
80
89
</varlistentry>
81
90
<varlistentry>
82
-
<term><parameter>ctor_args</parameter></term>
91
+
<term><parameter>constructorArgs</parameter></term>
83
92
<listitem>
84
93
<para>
85
-
Arguments of custom class constructor when the <parameter>fetch_style</parameter>
94
+
Arguments of custom class constructor when the <parameter>mode</parameter>
86
95
parameter is <constant>PDO::FETCH_CLASS</constant>.
87
96
</para>
88
97
</listitem>
89
98
</varlistentry>
99
+
<varlistentry>
100
+
<term><parameter>callback</parameter></term>
101
+
<listitem>
102
+
<para>
103
+
Used with <constant>PDO::FETCH_FUNC</constant>. Returns the results of calling the
104
+
specified function, using each row's columns as parameters in the call.
105
+
</para>
106
+
</listitem>
107
+
</varlistentry>
90
108
</variablelist>
91
109
</para>
92
110
</refsect1>
...
...
@@ -94,11 +112,11 @@
94
112
<refsect1 role="returnvalues">
95
113
&reftitle.returnvalues;
96
114
<para>
97
-
<function>PDOStatement::fetchAll</function> returns an array containing
115
+
<methodname>PDOStatement::fetchAll</methodname> returns an array containing
98
116
all of the remaining rows in the result set. The array represents each
99
117
row as either an array of column values or an object with properties
100
118
corresponding to each column name. An empty array is returned if there
101
-
are zero results to fetch, or &false; on failure.
119
+
are zero results to fetch.
102
120
</para>
103
121
<para>
104
122
Using this method to fetch large result sets will result in a heavy
...
...
@@ -110,6 +128,34 @@
110
128
</para>
111
129
</refsect1>
112
130

131
+
<refsect1 role="errors">
132
+
&reftitle.errors;
133
+
&pdo.errors;
134
+
</refsect1>
135
+

136
+
<refsect1 role="changelog">
137
+
&reftitle.changelog;
138
+
<informaltable>
139
+
<tgroup cols="2">
140
+
<thead>
141
+
<row>
142
+
<entry>&Version;</entry>
143
+
<entry>&Description;</entry>
144
+
</row>
145
+
</thead>
146
+
<tbody>
147
+
<row>
148
+
<entry>8.0.0</entry>
149
+
<entry>
150
+
This method always returns an &array; now, while previously &false; may have
151
+
been returned on failure.
152
+
</entry>
153
+
</row>
154
+
</tbody>
155
+
</tgroup>
156
+
</informaltable>
157
+
</refsect1>
158
+

113
159
<refsect1 role="examples">
114
160
&reftitle.examples;
115
161
<para>
...
...
@@ -121,7 +167,7 @@ $sth = $dbh->prepare("SELECT name, colour FROM fruit");
121
167
$sth->execute();
122
168

123
169
/* Fetch all of the remaining rows in the result set */
124
-
print("Fetch all of the remaining rows in the result set:\n");
170
+
print "Fetch all of the remaining rows in the result set:\n";
125
171
$result = $sth->fetchAll();
126
172
print_r($result);
127
173
?>
...
...
@@ -135,13 +181,21 @@ Array
135
181
(
136
182
[0] => Array
137
183
(
184
+
[name] => apple
185
+
[0] => apple
186
+
[colour] => red
187
+
[1] => red
188
+
)
189
+

190
+
[1] => Array
191
+
(
138
192
[name] => pear
139
193
[0] => pear
140
194
[colour] => green
141
195
[1] => green
142
196
)
143
197

144
-
[1] => Array
198
+
[2] => Array
145
199
(
146
200
[name] => watermelon
147
201
[0] => watermelon
...
...
@@ -231,7 +285,7 @@ array(3) {
231
285
["watermelon"]=>
232
286
array(1) {
233
287
[0]=>
234
-
string(5) "green"
288
+
string(5) "pink"
235
289
}
236
290
}
237
291

...
...
@@ -284,6 +338,20 @@ array(3) {
284
338
["colour"]=>
285
339
string(4) "pink"
286
340
}
341
+
[3]=>
342
+
object(fruit)#4 (2) {
343
+
["name"]=>
344
+
string(5) "apple"
345
+
["colour"]=>
346
+
string(3) "red"
347
+
}
348
+
[4]=>
349
+
object(fruit)#5 (2) {
350
+
["name"]=>
351
+
string(4) "pear"
352
+
["colour"]=>
353
+
string(5) "green"
354
+
}
287
355
}
288
356
]]>
289
357
</screen>
...
...
@@ -318,6 +386,10 @@ array(3) {
318
386
string(12) "pear: yellow"
319
387
[2]=>
320
388
string(16) "watermelon: pink"
389
+
[3]=>
390
+
string(10) "apple: red"
391
+
[4]=>
392
+
string(11) "pear: green"
321
393
}
322
394
]]>
323
395
</screen>
...
...
@@ -330,16 +402,15 @@ array(3) {
330
402
&reftitle.seealso;
331
403
<para>
332
404
<simplelist>
333
-
<member><function>PDO::query</function></member>
334
-
<member><function>PDOStatement::fetch</function></member>
335
-
<member><function>PDOStatement::fetchColumn</function></member>
336
-
<member><function>PDO::prepare</function></member>
337
-
<member><function>PDOStatement::setFetchMode</function></member>
405
+
<member><methodname>PDO::query</methodname></member>
406
+
<member><methodname>PDOStatement::fetch</methodname></member>
407
+
<member><methodname>PDOStatement::fetchColumn</methodname></member>
408
+
<member><methodname>PDO::prepare</methodname></member>
409
+
<member><methodname>PDOStatement::setFetchMode</methodname></member>
338
410
</simplelist>
339
411
</para>
340
412
</refsect1>
341
413
</refentry>
342
-

343
414
<!-- Keep this comment at the end of the file
344
415
Local variables:
345
416
mode: sgml
346
417