reference/pdo/pdostatement/fetchall.xml
28529d3539b850e870e3aa97570f4db0e53daa03
...
...
@@ -1,21 +1,37 @@
1
-
<?xml version="1.0" encoding="UTF-8"?>
1
+
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
3
<refentry xml:id="pdostatement.fetchall" xmlns="http://docbook.org/ns/docbook">
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>
13
-
<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>
12
+
<methodsynopsis role="PDOStatement">
13
+
<modifier>public</modifier> <type>array</type><methodname>PDOStatement::fetchAll</methodname>
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>column-index</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 have 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,10 +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
-
corresponding to each column name.
118
+
corresponding to each column name. An empty array is returned if there
119
+
are zero results to fetch.
101
120
</para>
102
121
<para>
103
122
Using this method to fetch large result sets will result in a heavy
...
...
@@ -109,6 +128,34 @@
109
128
</para>
110
129
</refsect1>
111
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
+

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

122
169
/* Fetch all of the remaining rows in the result set */
123
-
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";
124
171
$result = $sth->fetchAll();
125
172
print_r($result);
126
173
?>
...
...
@@ -134,17 +181,25 @@ Array
134
181
(
135
182
[0] => Array
136
183
(
137
-
[NAME] => pear
184
+
[name] => apple
185
+
[0] => apple
186
+
[colour] => red
187
+
[1] => red
188
+
)
189
+

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

143
-
[1] => Array
198
+
[2] => Array
144
199
(
145
-
[NAME] => watermelon
200
+
[name] => watermelon
146
201
[0] => watermelon
147
-
[COLOUR] => pink
202
+
[colour] => pink
148
203
[1] => pink
149
204
)
150
205

...
...
@@ -230,7 +285,7 @@ array(3) {
230
285
["watermelon"]=>
231
286
array(1) {
232
287
[0]=>
233
-
string(5) "green"
288
+
string(5) "pink"
234
289
}
235
290
}
236
291

...
...
@@ -283,6 +338,20 @@ array(3) {
283
338
["colour"]=>
284
339
string(4) "pink"
285
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
+
}
286
355
}
287
356
]]>
288
357
</screen>
...
...
@@ -317,6 +386,10 @@ array(3) {
317
386
string(12) "pear: yellow"
318
387
[2]=>
319
388
string(16) "watermelon: pink"
389
+
[3]=>
390
+
string(10) "apple: red"
391
+
[4]=>
392
+
string(11) "pear: green"
320
393
}
321
394
]]>
322
395
</screen>
...
...
@@ -329,16 +402,15 @@ array(3) {
329
402
&reftitle.seealso;
330
403
<para>
331
404
<simplelist>
332
-
<member><function>PDO::query</function></member>
333
-
<member><function>PDOStatement::fetch</function></member>
334
-
<member><function>PDOStatement::fetchColumn</function></member>
335
-
<member><function>PDO::prepare</function></member>
336
-
<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>
337
410
</simplelist>
338
411
</para>
339
412
</refsect1>
340
413
</refentry>
341
-

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