We have described in detail the usage of query language, but query language only solves the problem of query or operation condition, more cooperation also need to use the consistent operation method provided by model.
Introduced
Consistent operation can effectively improve the code definition and development efficiency of data access, and support all curd operations, but also a highlight of Thinkphp's ORM. The use is also relatively simple, if we now want to query a user table to meet the status of 1 of the first 10 records, and want to be sorted by the time of creation of users, the code is as follows:
$User->where (' Status=1 ')->order (' Create_time ')->limit ()->select ();
The Where, order, and limit methods here are called coherent operations, except that the Select method must be put to the last (since the Select method is not a coherent operation), the sequence of method invocations for a coherent operation is not sequential, for example, the following code is equivalent to the above:
$User->order (' create_time ')->limit->where (' Status=1 ')->select ();
It's not just that query methods can be used in a coherent operation, including all curd methods, such as:
$User->where (' id=1 ')->field (' id,http://www.aliyun.com/zixun/aggregation/11696.html ' >name,email ')-> Find (); $User->where (' Status=1 and Id=1 ')->delete ();
A coherent operation is performed only when the query or operation is valid, and when completed, it automatically empties all the values of the consecutive operation (there are individual special consecutive operations that record current values, such as cache coherence operations). In short, the results of a coherent operation are not brought into subsequent queries.
The consistent operating methods supported by the system are:
The type of parameter supported by the method where the definition string, array, and object table for the query or update criteria are used to define the 6184.html ">" table name string and array alias that is used to define the alias string for the current datasheet before the new or updated data Data object assignment Array and Object field define the fields to query (support field exclusions) string and array order for the result sort string and array limit to limit the number of query results string and number page for query paging (internally converts to limit) strings and numbers The group support string used for the query has the having support string used for the query join* the join support string and array for the query union* the union of the query supports strings, arrays, and objects distinct for the query's di STINCT supports Boolean lock for database locking mechanism Boolean cache for query caching supports multiple parameters (later in the cache section) relation for associative queries (requiring association model extension support) string validate for data automatic validation arrays AUT O for Data AutoComplete array filter for data filtering string scope* for named range strings, arrays
All consecutive operations return the current model instance object (this), with the * identity representation supported multiple invocations.
Usage
Since the use of a coherent operation often involves the use of multiple methods, the following is a general introduction to the basic usage of each of these consecutive operations:
WHERE
Where is used to query or update the definition usage where ($where) parameter where (MUST): query or Operation condition, support string, array, and object return value current model instance Note If you do not call the Where method, the default does not perform the update and delete operations
The Where method is the most consistent method of operation, for more detailed use refer to the Quick Start query language.