pq\Statement docs
[mdref/mdref-pq] / pq / Statement / bind.md
1 # void pq\Statement::bind(int $param_no, mixed &$param_ref)
2
3 Bind a variable to an input parameter.
4
5 ## Params:
6
7 * int $param_no
8 The parameter index to bind to.
9 * mixed &$param_ref
10 The variable to bind.
11
12 ## Throws:
13
14 * pq\Exception\InvalidArgumentException
15 * pq\Exception\BadMethodCallException
16
17
18 ## Example:
19
20 <?php
21
22 $connection = new pq\Connection;
23 $statement = $connection->prepare("st1",
24 "SELECT \$1 as first, \$2 as second", [pq\Types::INT4, pq\Types::INT4]);
25
26 $statement->bind(1, $first);
27 $statement->bind(2, $second);
28
29 $first = 1;
30 $second = 2;
31
32 $result = $statement->exec();
33 foreach ($result->fetchRow(pq\Result::FETCH_ASSOC) as $col => $val) {
34 printf("%10s = %s\n", $col, $val);
35 }
36
37 ?>
38
39 Yields:
40
41 first = 1
42 second = 2