pq\Result docs
[mdref/mdref-pq] / pq / Connection / on.md
1 # int pq\Connection::on(string $event, callable $callback)
2
3 Listen for an event.
4
5 ## Params:
6
7 * string $event
8 Any pq\Connection::EVENT_*.
9 * callable $callback as function(pq\Connection $c[, pq\Result $r)
10 The callback to invoke on event.
11
12 ## Returns:
13
14 * int, number of previously attached event listeners.
15
16 ## Throws:
17
18 * pq\Exception\InvalidArgumentException
19
20 ## Example:
21
22 <?php
23
24 $connection = new pq\Connection;
25 $connection->on(pq\Connection::EVENT_RESULT, function($c, $r) {
26 printf("Got result with %d rows\n", $r->numRows);
27 });
28 $connection->exec("SELECT * FROM generate_series(1,3)");
29
30 ?>
31
32 Yields:
33
34 Got result with 3 rows