tp5 database - chaining

Chaining

Chaining method provided by the database, can effectively improve the development efficiency and clarity of code data access, and supports all CURD operations.

Using relatively simple, if we now want to query a User table of state meet for the first 10 records 1, and want to follow the creation time of the user's sort code is as follows:

Db::table('think_user')
    ->where('status',1)
    ->order('create_time')
    ->limit(10)
    ->select();

Here where, orderand limitthe method was called chaining method, except that the method must select the last placed outside (because the select method is not chaining method), a method of operation of the chain has no calling sequence, for example, the following and the above equivalent code is:

Db::table('think_user')
    ->order('create_time')
    ->limit(10)
    ->where('status',1)
    ->select();

In fact, not only you can use the query methods consistent operations, including all CURD methods can be used, for example:

Db::table('think_user')
    ->where('id',1)
    ->field('id,name,email')
    ->find(); 
Db::table('think_user')
    ->where('status',1)
    ->where('id',1)
    ->delete();

Chain automatically clears all by value chain operations after the completion of inquiry. In short, the results of operations of the chain will not inquire into the back of the other.

The system supports chaining methods are:

Coherent operation effect Supported parameter types

where*

AND for query Strings, arrays and objects
whereOr* Queries for OR Strings, arrays and objects
wheretime* Time for quick and easy reference date String
table Defines the name of a data table to be operated Strings and arrays
alias The current data table is used to define an alias String
field* Is used to define the fields you want to query (support field excluded) Strings and arrays
order* It used to sort the results Strings and arrays
limit Used to limit the number of query results Strings and numbers
page Used to query paging (internal converted into limit) Strings and numbers
group For group support for query String
having Support for having the query String
join* Support for join queries Strings and arrays
union* For union support for queries Strings, arrays and objects
view* To view query Strings, arrays
distinct Support for distinct queries Boolean value
lock For the locking mechanism of the database Boolean value
cache For query cache Support for multiple parameters
relation* For related queries String
with* Association for preloading Strings, arrays
bind* Data for the binding operation Array or more parameters
comment For SQL comment String
force Force index for the data set String
master Reading data for setting the master Boolean value
strict Whether to set strict detection field name exists Boolean value
sequence Increment sequence for setting the name of Pgsql String
failException Whether or not to set the query to the data thrown Boolean value
partition Information for setting a sub-table Array of strings

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

All operations are consistent returns the current instance of the object model (this), in which marked with * support multiple calls.

Guess you like

Origin www.cnblogs.com/fei-H/p/11763769.html