partial QueryWriter
[mdref/mdref-pq-gateway] / pq-gateway / pq / Query / Writer / criteria.md
1 # pq\Query\Writer pq\Query\Writer::criteria(array $criteria)
2
3 Write nested AND/OR criteria to the query string.
4
5 ## Params:
6
7 * array $criteria
8 Nested AND/OR criteria.
9
10 ## Returns:
11
12 * pq\Query\Writer, self.
13
14 ## Example:
15
16 <?php
17
18 use pq\Query;
19
20 $q = new Query\Writer;
21 $q->write("select * from account where")
22 ->criteria([
23 ["id >" => 1, "id <" => 5],
24 ["name =" => "mike"]
25 ]);
26
27 var_dump((string) $q, $q->getParams());
28
29 ?>
30
31 Yields:
32
33 string(84) "select * from account where ( ( ( id > $1 ) AND ( id < $2 ) ) OR ( ( name = $3 ) ) )"
34 array(3) {
35 [0]=>
36 int(1)
37 [1]=>
38 int(5)
39 [2]=>
40 string(4) "mike"
41 }