fix typo in link
[mdref/mdref-pq] / pq / Statement / __construct.md
1 # void pq\Statement::__construct(pq\Connection $conn, string $name, string $query[, array $types = NULL[, bool $async = FALSE]])
2
3 Prepare a new statement.
4 See pq\Connection::prepare().
5
6 ## Params:
7
8 * pq\Connection $conn
9 The connection to prepare the statement on.
10 * string $name
11 The name identifying this statement.
12 * string $query
13 The actual query to prepare.
14 * Optional array $types = NULL
15 A list of corresponding query parameter type OIDs.
16 * Optional bool $async = FALSE
17 Whether to prepare the statement [asynchronously](pq/Connection/: Asynchronous Usage).
18
19 ## Throws:
20
21 * pq\Exception\InvalidArgumentException
22 * pq\Exception\BadMethodCallException
23 * pq\Exception\RuntimeException
24 * pq\Exception\DomainException
25
26 ## Example:
27
28 <?php
29
30 $connection = new pq\Connection;
31 $statement = new pq\Statement(
32 $connection,
33 "my_statement",
34 "SELECT \$1",
35 [pq\Types::INT4]
36 );
37
38 $result = $statement->exec([123]);
39 $result->fetchCol($col);
40
41 echo "Got: $col\n";
42
43 ?>
44
45 Yields:
46
47 Got: 123