typo
[mdref/mdref-pq] / pq / Cursor / fetch.md
1 # pq\Result pq\Cursor::fetch([string $spec = "1"])
2
3 Fetch rows from the cursor.
4 See pq\Cursor::move().
5
6 ## Params:
7
8 * Optional string $spec = "1"
9 What to fetch.
10
11 ### Fetch argument:
12
13 FETCH and MOVE usually accepts arguments like the following, where `count` is the number of rows:
14
15 * NEXT
16 * PRIOR
17 * FIRST
18 * LAST
19 * ABSOLUTE `count`
20 * RELATIVE `count`
21 * `count`
22 * ALL
23 * FORWARD
24 * FORWARD `count`
25 * FORWARD ALL
26 * BACKWARD
27 * BACKWARD `count`
28 * BACKWARD ALL
29
30 See the [official PostgreSQL documentaion](http://www.postgresql.org/docs/current/static/sql-fetch.html) for details.
31
32 ## Returns:
33
34 * pq\Result, the fetched row(s).
35
36 ## Throws:
37
38 * pq\Exception\InvalidArgumentException
39 * pq\Exception\BadMethodCallException
40 * pq\Exception\RuntimeException
41
42 ## Example:
43
44 <?php
45
46 $c = new pq\Connection;
47 $p = new pq\Cursor($c, "mycursor", pq\Cursor::WITH_HOLD,
48 "SELECT * FROM generate_series(0,29) s WHERE (s%2)=0");
49
50 for ($r = $p->fetch(2); $r->numRows; $p->move(1), $r = $p->fetch(2)) {
51 foreach ($r as $row) {
52 foreach ($row as $col) {
53 echo " $col";
54 }
55 echo "\n";
56 }
57 }
58
59 ?>
60
61 Yields:
62
63 0
64 2
65 6
66 8
67 12
68 14
69 18
70 20
71 24
72 26