add example
[mdref/mdref-pq] / pq / Connection / execAsync.md
1 # void pq\Connection::exec(string $query[, callable $callback])
2
3 [Asynchronously](pq/Connection/: Asynchronous Usage) [execute an SQL query](pq/Connection: Executing Queries) on the connection.
4
5 > ***NOTE***:
6 If pq\Connection::$unbuffered is TRUE, each call to pq\Connection::getResult() will generate a distinct pq\Result containing exactly one row.
7
8 ## Params:
9
10 * string $query
11 The query to send to the server.
12 * Optional callable $callback as function(pq\Result $res)
13 The callback to execute when the query finishes.
14
15 ## Throws:
16
17 * pq\Exception\InvalidArgumentException
18 * pq\Exception\BadMethodCallException
19 * pq\Exception\RuntimeException
20
21 ## Example:
22
23 <?php
24
25 $connection = new pq\Connection;
26 $connection->execAsync("SELECT 1", function($res) {
27 //...
28 });
29 $connection->getResult();
30
31 ?>