3c89d1be3ed29593bc5d7bd792768e605a126489
[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 The criteria can either be a simple accociative array, where the keys build the left hand operand plus the operator and the values make up the right hand operand and will be passed to pq\Query\Writer::param(). All concatenated together by AND clauses.
6
7 Using multiple arrays, the above logic will be applied to each array and then concatenated by OR clauses.
8
9 ## Params:
10
11 * array $criteria
12 Nested AND/OR criteria.
13
14 ## Returns:
15
16 * pq\Query\Writer, self.
17
18 ## Example:
19
20 <?php
21
22 use pq\Query;
23
24 $q = new Query\Writer;
25 $q->write("select * from account where")
26 ->criteria([
27 ["id >" => 1, "id <" => 5],
28 ["name =" => "mike"]
29 ]);
30
31 var_dump((string) $q, $q->getParams());
32
33 ?>
34
35 Yields:
36
37 string(84) "select * from account where ( ( ( id > $1 ) AND ( id < $2 ) ) OR ( ( name = $3 ) ) )"
38 array(3) {
39 [0]=>
40 int(1)
41 [1]=>
42 int(5)
43 [2]=>
44 string(4) "mike"
45 }