Case Analysis of thinkphp Coherent Operation

  • 2021-08-05 09:27:21
  • OfStack

This paper analyzes the usage of thinkphp coherent operation with examples. Share it for your reference. The specific analysis is as follows:

1. Commonly used coherent operation, which can be used in succession but has no sequence. The last 1 must have methods select, updata, delete and find

1. where: Help us set query criteria

2. order: Sort the results

$arr=$m->order('id desc')->select();// String method , The default is asc Ascending order, plus desc Change to descending order   
$arr=$m->order(array('id'=>'desc','sex'=>'asc'))->select(); // Array method

3. limit: Limiting results
limit(2,5)// From the first 2 Strip removal 5 Article   
limit('2,5')// Note string formal parameter  
limit(10)// Equivalent to limit(0,10) The default is from 0 Begin

4. field: Setting query fields
field('username as name,id') // Pass characters and modify field names   
field(array('username'=>'name','id')// Pass array query and modify field name  
field('id',true) // Gets other than id All fields other than

5. table: Tables

6. group: Grouping

7. having: Grouping related

2. Supplement

alias is used to define an alias string for the current data table

page is used to query paging (internally converted to limit) strings and numbers

join * join for queries supports strings and arrays

union * union for queries supports strings, arrays, and objects

distinct distinct for queries supports Boolean values

lock Locking Mechanism for Database Boolean

cache is used to query cache support for multiple parameters (described in more detail in the cache section later)

relation is used for association queries (requiring association model extension support) strings

validate for automatic data validation arrays

auto is used for data auto-completion arrays

filter for data filtering strings

scope* is used to name range strings, arrays

I hope this article is helpful to everyone's ThinkPHP framework programming.


Related articles: