reference/pdo/pdostatement/fetch.xml
daf4cc624df3c21d472149725feb377b1beedb04
...
...
@@ -9,16 +9,16 @@
9
9
</refnamediv>
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<methodsynopsis>
12
+
<methodsynopsis role="PDOStatement">
13
13
<modifier>public</modifier> <type>mixed</type><methodname>PDOStatement::fetch</methodname>
14
-
<methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam>
15
-
<methodparam choice="opt"><type>int</type><parameter>cursor_orientation</parameter><initializer>PDO::FETCH_ORI_NEXT</initializer></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter>cursor_offset</parameter><initializer>0</initializer></methodparam>
14
+
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer>PDO::FETCH_DEFAULT</initializer></methodparam>
15
+
<methodparam choice="opt"><type>int</type><parameter>cursorOrientation</parameter><initializer>PDO::FETCH_ORI_NEXT</initializer></methodparam>
16
+
<methodparam choice="opt"><type>int</type><parameter>cursorOffset</parameter><initializer>0</initializer></methodparam>
17
17
</methodsynopsis>
18
18

19
19
<para>
20
20
Fetches a row from a result set associated with a PDOStatement object. The
21
-
<parameter>fetch_style</parameter> parameter determines how PDO returns
21
+
<parameter>mode</parameter> parameter determines how PDO returns
22
22
the row.
23
23
</para>
24
24
</refsect1>
...
...
@@ -28,7 +28,7 @@
28
28
<para>
29
29
<variablelist>
30
30
<varlistentry>
31
-
<term><parameter>fetch_style</parameter></term>
31
+
<term><parameter>mode</parameter></term>
32
32
<listitem>
33
33
<para>
34
34
Controls how the next row will be returned to the caller. This value
...
...
@@ -48,7 +48,7 @@
48
48
<listitem><para>
49
49
<literal>PDO::FETCH_BOUND</literal>: returns &true; and assigns the
50
50
values of the columns in your result set to the PHP variables to which
51
-
they were bound with the <function>PDOStatement::bindColumn</function>
51
+
they were bound with the <methodname>PDOStatement::bindColumn</methodname>
52
52
method
53
53
</para></listitem>
54
54
<listitem><para>
...
...
@@ -56,7 +56,7 @@
56
56
requested class, mapping the columns of the result set to named
57
57
properties in the class, and calling the constructor afterwards, unless
58
58
<literal>PDO::FETCH_PROPS_LATE</literal> is also given.
59
-
If <parameter>fetch_style</parameter>
59
+
If <parameter>mode</parameter>
60
60
includes PDO::FETCH_CLASSTYPE (e.g. <literal>PDO::FETCH_CLASS |
61
61
PDO::FETCH_CLASSTYPE</literal>) then the name of the class is
62
62
determined from a value of the first column.
...
...
@@ -69,7 +69,8 @@
69
69
<listitem><para>
70
70
<literal>PDO::FETCH_LAZY</literal>: combines
71
71
<literal>PDO::FETCH_BOTH</literal> and <literal>PDO::FETCH_OBJ</literal>,
72
-
creating the object variable names as they are accessed
72
+
and is returning a <classname>PDORow</classname> object
73
+
which is creating the object property names as they are accessed.
73
74
</para></listitem>
74
75
<listitem><para>
75
76
<literal>PDO::FETCH_NAMED</literal>: returns an array with the same
...
...
@@ -98,7 +99,7 @@
98
99
</listitem>
99
100
</varlistentry>
100
101
<varlistentry>
101
-
<term><parameter>cursor_orientation</parameter></term>
102
+
<term><parameter>cursorOrientation</parameter></term>
102
103
<listitem>
103
104
<para>
104
105
For a PDOStatement object representing a scrollable cursor, this
...
...
@@ -108,25 +109,25 @@
108
109
scrollable cursor for your PDOStatement object, you must set the
109
110
<literal>PDO::ATTR_CURSOR</literal> attribute to
110
111
<literal>PDO::CURSOR_SCROLL</literal> when you prepare the SQL
111
-
statement with <function>PDO::prepare</function>.
112
+
statement with <methodname>PDO::prepare</methodname>.
112
113
</para>
113
114
</listitem>
114
115
</varlistentry>
115
116
<varlistentry>
116
-
<term><parameter>offset</parameter></term>
117
+
<term><parameter>cursorOffset</parameter></term>
117
118
<listitem>
118
119
<para>
119
120
For a PDOStatement object representing a scrollable cursor for which
120
-
the <literal>cursor_orientation</literal> parameter is set to
121
+
the <parameter>cursorOrientation</parameter> parameter is set to
121
122
<literal>PDO::FETCH_ORI_ABS</literal>, this value specifies the
122
123
absolute number of the row in the result set that shall be fetched.
123
124
</para>
124
125
<para>
125
126
For a PDOStatement object representing a scrollable cursor for which
126
-
the <literal>cursor_orientation</literal> parameter is set to
127
+
the <parameter>cursorOrientation</parameter> parameter is set to
127
128
<literal>PDO::FETCH_ORI_REL</literal>, this value specifies the
128
129
row to fetch relative to the cursor position before
129
-
<function>PDOStatement::fetch</function> was called.
130
+
<methodname>PDOStatement::fetch</methodname> was called.
130
131
</para>
131
132
</listitem>
132
133
</varlistentry>
...
...
@@ -138,10 +139,15 @@
138
139
&reftitle.returnvalues;
139
140
<para>
140
141
The return value of this function on success depends on the fetch type. In
141
-
all cases, &false; is returned on failure.
142
+
all cases, &false; is returned on failure or if there are no more rows.
142
143
</para>
143
144
</refsect1>
144
145

146
+
<refsect1 role="errors">
147
+
&reftitle.errors;
148
+
&pdo.errors;
149
+
</refsect1>
150
+

145
151
<refsect1 role="examples">
146
152
&reftitle.examples;
147
153
<para>
...
...
@@ -153,29 +159,29 @@ $sth = $dbh->prepare("SELECT name, colour FROM fruit");
153
159
$sth->execute();
154
160

155
161
/* Exercise PDOStatement::fetch styles */
156
-
print("PDO::FETCH_ASSOC: ");
157
-
print("Return next row as an array indexed by column name\n");
162
+
print "PDO::FETCH_ASSOC: ";
163
+
print "Return next row as an array indexed by column name\n";
158
164
$result = $sth->fetch(PDO::FETCH_ASSOC);
159
165
print_r($result);
160
-
print("\n");
166
+
print "\n";
161
167

162
-
print("PDO::FETCH_BOTH: ");
163
-
print("Return next row as an array indexed by both column name and number\n");
168
+
print "PDO::FETCH_BOTH: ";
169
+
print "Return next row as an array indexed by both column name and number\n";
164
170
$result = $sth->fetch(PDO::FETCH_BOTH);
165
171
print_r($result);
166
-
print("\n");
172
+
print "\n";
167
173

168
-
print("PDO::FETCH_LAZY: ");
169
-
print("Return next row as an anonymous object with column names as properties\n");
174
+
print "PDO::FETCH_LAZY: ";
175
+
print "Return next row as a PDORow object with column names as properties\n";
170
176
$result = $sth->fetch(PDO::FETCH_LAZY);
171
177
print_r($result);
172
-
print("\n");
178
+
print "\n";
173
179

174
-
print("PDO::FETCH_OBJ: ");
175
-
print("Return next row as an anonymous object with column names as properties\n");
180
+
print "PDO::FETCH_OBJ: ";
181
+
print "Return next row as an anonymous object with column names as properties\n";
176
182
$result = $sth->fetch(PDO::FETCH_OBJ);
177
183
print $result->name;
178
-
print("\n");
184
+
print "\n";
179
185
?>
180
186
]]>
181
187
</programlisting>
...
...
@@ -198,7 +204,7 @@ Array
198
204
[1] => yellow
199
205
)
200
206

201
-
PDO::FETCH_LAZY: Return next row as an anonymous object with column names as properties
207
+
PDO::FETCH_LAZY: Return next row as a PDORow object with column names as properties
202
208
PDORow Object
203
209
(
204
210
[name] => orange
...
...
@@ -215,35 +221,23 @@ kiwi
215
221
<![CDATA[
216
222
<?php
217
223
function readDataForwards($dbh) {
218
-
$sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY BET';
219
-
try {
224
+
$sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY BET';
220
225
$stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
221
226
$stmt->execute();
222
227
while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
223
-
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
224
-
print $data;
228
+
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
229
+
print $data;
225
230
}
226
-
$stmt = null;
227
-
}
228
-
catch (PDOException $e) {
229
-
print $e->getMessage();
230
-
}
231
231
}
232
232
function readDataBackwards($dbh) {
233
-
$sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY bet';
234
-
try {
233
+
$sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY bet';
235
234
$stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
236
235
$stmt->execute();
237
236
$row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST);
238
237
do {
239
-
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
240
-
print $data;
238
+
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
239
+
print $data;
241
240
} while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR));
242
-
$stmt = null;
243
-
}
244
-
catch (PDOException $e) {
245
-
print $e->getMessage();
246
-
}
247
241
}
248
242

249
243
print "Reading forwards:\n";
...
...
@@ -327,17 +321,16 @@ I am Bob.
327
321
&reftitle.seealso;
328
322
<para>
329
323
<simplelist>
330
-
<member><function>PDO::prepare</function></member>
331
-
<member><function>PDOStatement::execute</function></member>
332
-
<member><function>PDOStatement::fetchAll</function></member>
333
-
<member><function>PDOStatement::fetchColumn</function></member>
334
-
<member><function>PDOStatement::fetchObject</function></member>
335
-
<member><function>PDOStatement::setFetchMode</function></member>
324
+
<member><methodname>PDO::prepare</methodname></member>
325
+
<member><methodname>PDOStatement::execute</methodname></member>
326
+
<member><methodname>PDOStatement::fetchAll</methodname></member>
327
+
<member><methodname>PDOStatement::fetchColumn</methodname></member>
328
+
<member><methodname>PDOStatement::fetchObject</methodname></member>
329
+
<member><methodname>PDOStatement::setFetchMode</methodname></member>
336
330
</simplelist>
337
331
</para>
338
332
</refsect1>
339
333
</refentry>
340
-

341
334
<!-- Keep this comment at the end of the file
342
335
Local variables:
343
336
mode: sgml
344
337