pq\LOB docs
[mdref/mdref-pq] / pq / Connection / declare.md
1 # pq\Cursor pq\Connection::declare(string $name, int $flags, string $query)
2
3 Declare a cursor for a query.
4
5 ## Params:
6
7 * string $name
8 The identifying name of the cursor.
9 * int $flags
10 Any combination of pq\Cursor constants.
11 * string $query
12 The query for which to open a cursor.
13
14 ## Returns:
15
16 * pq\Cursor, an open cursor instance.
17
18 ## Throws:
19
20 * pq\Exception\InvalidArgumentException
21 * pq\Exception\RuntimeException
22 * pq\Exception\BadMethodCallException
23
24 ## Example:
25
26 <?php
27
28 $connection = new pq\Connection;
29
30 $cursor = $connection->declare("example", pq\Cursor::WITH_HOLD,
31 "SELECT * FROM generate_series(0,29) s WHERE (s%2)=0");
32
33 for ( $result = $cursor->fetch(2);
34 $result->numRows;
35 $cursor->move(1), $result = $cursor->fetch(2)) {
36 foreach ($result as $row) {
37 foreach ($row as $col) {
38 echo " $col";
39 }
40 echo "\n";
41 }
42 }
43
44 ?>
45
46 Yields:
47
48 0
49 2
50 6
51 8
52 12
53 14
54 18
55 20
56 24
57 26