d5dda10f8babfac70a722da5c46449f608248934
[mdref/mdref-pq-gateway] / find.md
1 # mixed pq\Gateway\Table::find([array $where = NULL[, string $order = NULL[, int $limit = 0[, int $offset = 0[, string $lock = NULL]]]]])
2
3 Find rows in the table.
4 See pq\Gateway\Table::execute() and pq\Gateway\Table::onResult().
5
6 ## Params:
7
8 * Optional array $where = NULL
9 Lookup criteria.
10 * Optional string $order = NULL
11 Sorting clauses.
12 * Optional int $limit = 0
13 A row count limit.
14 * Optional int $offset = 0
15 A row count offset.
16 * Optional string $lock = NULL
17 A FOR lock clause (SHARE/UPDATE/KEY SHARE/NO KEY UPDATE).
18
19 ## Returns:
20
21 * a [deferred promise of React/Promise](https://github.com/reactphp/promise#deferred-1), when using pq\Query\AsyncExecutor, the asynchronous executor.
22 Else:
23 * pq\Result, if pq\Result::$status != pq\Result::TUPLES_OK.
24 * pq\Result, if the rowset prototype pq\Gateway\Table::$rowset is empty.
25 * pq\Gateway\Rowset, an instance of the rowset prototype.
26
27 ## Example:
28
29 <?php
30
31 use pq\Gateway\Table;
32
33 $table = new Table("account_email");
34 $transaction = $table->getConnection()->startTransaction();
35
36 $rowset = $table->find(["email=" => "mike@php.net"], null, 0, 0, "UPDATE");
37
38 $rowset->apply(function(pq\Gateway\Row $row) {
39 $row->email = "mike@PHP.net";
40 });
41
42 $rowset->update(false);
43 $transaction->commit();
44
45 ?>