document x.1.0 changes
[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 * pq\Exception\BadMethodCallException
20
21 ## Example:
22
23 <?php
24
25 $connection = new pq\Connection;
26 $connection->on(pq\Connection::EVENT_RESULT, function($c, $r) {
27 printf("Got result with %d rows\n", $r->numRows);
28 });
29 $connection->exec("SELECT * FROM generate_series(1,3)");
30
31 ?>
32
33 Yields:
34
35 Got result with 3 rows