pq\Transaction docs
[mdref/mdref-pq] / pq / Result / fetchRow.md
1 # mixed pq\Result::fetchRow([int $fetch_type = pq\Result::$fetchType])
2
3 Iteratively fetch a row.
4
5 ## Params:
6
7 * Optional int $fetch_type = pq\Result::$fetchType
8 The type the return value should have, see pq\Result::FETCH_* constants.
9
10 ## Returns:
11
12 * array, numerically indexed for pq\Result::FETCH_ARRAY
13 * array, associatively indexed for pq\Result::FETCH_ASSOC
14 * object, stdClass instance for pq\Result::FETCH_OBJECT
15 * NULL, when iteration ends.
16
17 ## Throws:
18
19 * pq\Exception\InvalidArgumentException
20 * pq\Exception\BadMethodCallException
21 * pq\Exception\RuntimeException
22
23 ## Example:
24
25 <?php
26
27 try {
28 $connection = new pq\Connection;
29
30 $result = $connection->exec("SELECT id, name, email FROM accounts WHERE email LIKE '_@%'");
31
32 while (list($id, $name, $email) = $result->fetchRow()) {
33 echo "ID: {$id}\n";
34 echo "Name: {$name}\n";
35 echo "Mail: {$email}\n\n";
36 }
37 } catch (\pq\Exception $e) {
38 echo $e->getMessage(), "\n";
39 }
40
41 ?>