h1 -> h2 for Throws
[mdref/mdref-pq] / pq / Result / map.md
1 # array pq\Result::map([mixed $keys = 0[, mixed $vals = NULL]])
2
3 Fetch the complete result set as a simple map, a *multi dimensional array*, each dimension indexed by a column.
4
5 ## Params:
6
7 * Optional mixed $keys = 0
8 The the column indices/names used to index the map.
9 * Optional mixed $vals = NULL
10 The column indices/names which should build up the leaf entry of the map.
11
12 ## Returns:
13
14 * array, the mapped columns.
15
16 ## Throws:
17
18 * pq\Exception\InvalidArgumentException
19 * pq\Exception\BadMethodCallException
20 * pq\Exception\RuntimeException
21
22 ## Example:
23
24 <?php
25
26 try {
27 $connection = new pq\Connection;
28
29 $result = $connection->exec("SELECT a,b,c from generate_series(1,3) a,
30 generate_series(4,6) b,
31 generate_series(7,9) c");
32
33 foreach($result->map(array(0,1,2)) as $a => $aa) {
34 foreach ($aa as $b => $bb) {
35 foreach ($bb as $c => $res) {
36 printf("%s,%s,%s = %s ", $a, $b, $c, implode(",", $res));
37 }
38 printf("\n");
39 }
40 printf("\n");
41 }
42 } catch (\pq\Exception $e) {
43 echo $e->getMessage(), "\n";
44 }
45
46 ?>
47
48
49 It should produce:
50
51 1,4,7 = 1,4,7 1,4,8 = 1,4,8 1,4,9 = 1,4,9
52 1,5,7 = 1,5,7 1,5,8 = 1,5,8 1,5,9 = 1,5,9
53 1,6,7 = 1,6,7 1,6,8 = 1,6,8 1,6,9 = 1,6,9
54
55 2,4,7 = 2,4,7 2,4,8 = 2,4,8 2,4,9 = 2,4,9 // This should help generate maps
56 2,5,7 = 2,5,7 2,5,8 = 2,5,8 2,5,9 = 2,5,9 // of f.e. statistical data with
57 2,6,7 = 2,6,7 2,6,8 = 2,6,8 2,6,9 = 2,6,9 // some GROUP BYs etc.
58
59 3,4,7 = 3,4,7 3,4,8 = 3,4,8 3,4,9 = 3,4,9
60 3,5,7 = 3,5,7 3,5,8 = 3,5,8 3,5,9 = 3,5,9
61 3,6,7 = 3,6,7 3,6,8 = 3,6,8 3,6,9 = 3,6,9