Mastering Thinkphp3.2.0----Coherent operation

Source: Internet
Author: User

In fact, in TP, each key word in the statement is encapsulated into a function, the function of each of the functions of the evolution of the keyword is called coherent operation. Just pay attention to the differences in the direct parameter passing of each function.

Furthermore, not all functions can be operated consistently!!! such as SELECT ()

A set of functions that support coherent operations

Do not deliberately to remember, the code is knocked out, as long as the use of more than the problem

Example:

1 //Array Manipulation2 $user= M (' User ');3 Var_dump($user->select (Array(' where ' \ = ' id in (1,2,3,4) ', ' limit ' = ' 2 ',//not coherent operation4' Order ' = ' Date DESC ')));5 //curd treatment, curd will be explained in a special section6 $user= M (' User ');7 Var_dump($user->where (' id=1 ')find ());8 Var_dump($user->where (' id=7 ')->delete ());

Detailed Description:

1.where, as already mentioned, refer to the front

2.order

1 //Reverse2 $user= M (' User ');3 $map[' id '] =Array(' eq ', 1);4 Var_dump($user->order (' id desc ')->select ());//positive Order default or ASC5 //Second sort6 Var_dump($user->order (' ID desc,email desc ')Select ());7 PS: First by ID reverse, and then by email reverse8 //array form prevents field from conflicting with MySQL keyword9 $user= M (' User ');Ten $map[' id '] =Array(' eq ', 1); One Var_dump($user->order (Array(' id ' = ' DESC ') ') ->select ());

3.field

1 //Show ID and user two fields only2 $user= M (' User ');3 Var_dump($user->field (' id, user ')Select ());4 //using SQL functions and aliases5 $user= M (' User ');6 var_dump ($user->field (' SUM (ID) as count, user ')->select ()); 7 //using array parameters with SQL functions8 $user= M (' User ');9 Var_dump($user->field (Array(' id ', ' Left (user,3) ' = ' left_user ')) -SeleTen CT ()); One //Get all fields A $user= M (' User '); - Var_dump($user->field ()->select ());//you can pass in the * number, or omit the method - //For writing the $user= M (' User '); - $user->field (' User,email ')->create ();//Curd will learn in special chapters.

4.limit

1 $user = M (' user '); 2 Var_dump ($user->limit (2),Select ()); 3 // Paging Query 4 $user = M (' user '); 5 Var_dump ($user//2, 2, 4,2

5.page

1 // Page pagination 2 $user = M (' user '); 3 Var_dump ($user//2, 2, 3,2

6.table

1 //Toggle Data Table2 $user= M (' User ');3 Var_dump($user->table (' Think_info ')Select ());4 //get simplified table name5 $user= M (' User ');6 var_dump ($user->table (' __user__ ')->select ());//__info__ Fair 7 //Multi-table query8 $user= M (' User ');9 Var_dump($user->field (' a.id,b.id ')->table ('__user__ a,__info__TenB ')Select ()); One //Multi-table queries, using array form to avoid keyword collisions A $user= M (' User '); - Var_dump($user->field (' a.id,b.id ')->table (Array(' think_user ' = ' a ', -' Think_info ' = ' B '))->select ());

7.alias

1 Alias to set the data table alias 2 // Setting Aliases 3 $user = M (' user '); 4 Var_dump ($user->alias (' a ')->select ());

8.group

1 // The group method is typically used to group result sets that combine function statistics.  2//Group statistics 3$user = M (' user '); 4 Var_dump ($user->field (' User,max (ID) ')->group (' id ')->select ());

9.having

1 // The having method is typically used in conjunction with the group method to complete the filtering of data from the grouped results.  2//grouping statistics combined withhaving3$user = M (' user '); 4 Var_dump ($user->field (' User,max (ID) ')->group (' id ')->having (' id>2 '),5 Select ());

10.comment

1 // The comment method is used to annotate SQL statements 2 //sql Notes 3 $user = M (' user '); 4 Var_dump ($user->comment (' All Users ')->select ());

11.join

1 //the Join method is used for connection queries of multiple tables. 2 //join Multiple Table association, default is inner JOIN3 $user= M (' User ');4 Var_dump($user-Join(‘think_user on think_info.id =5Think_user.id ')->select ());//__user__ and __info__ instead6 //right, left, full7 Var_dump($user-Join(‘think_user on think_info.id =8Think_user.id ', ' right ')->select ());

12.uinon

1 // Union method for merging result sets of multiple SELECT 2 //Merge Multiple Select result Sets 3 $user = M (' user '); 4 Var_dump ($user->union ("SELECT * from Think_info")->select ());

13.distinct

1 // the distinct method is used to return only different values 2 //returns non-repeating columns 3 $user = M (' user '); 4 Var_dump ($usertrue)->field (' user ')->select ());

14.cache

1 // cache for query caching operations 2 //Query cache, second read cache contents 3 $user = M (' user '); 4 Var_dump ($usertrue)->select ());

15. Naming Ranges

Mastering Thinkphp3.2.0----Coherent operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.