Original: thinkphp framework model coherent operation (eight)
Thinkphp's consistent operation is also flexible:
* There may be some MySQL functions here are not all listed, we can extrapolate, the form of similar
I. Common and consistent operation
1.where
Help us set query criteria
2.order
Sort the results
$arr = $m->order (' id desc ')->select ();
$arr = $m->order (array (' id ' = ' desc ', ' sex ' = ' asc '))->select (); Sort multiple fields
Array form Query sort
$data [' id ']=array (2,3,4, ' or '); Check id=2 or id=3 or id=4
$arr = $user->where ($data)->order (' id desc ')->select ();
3.limit
Limit results
Limit (2,5)//starting from 2 strip 3
Or
Limit (' 2,5 ')
Limit (//limit) (0,10)
The method provided does not have a sequence of points, but in the end it must be select
$arr = $m->order (array (' id ' = ' desc ', ' sex ' = ' asc '))->limit ()->select ();
4.field
Set query fields
Field (' username as Name,id ')//Alias
Or
Field (Array (' username ' = ' name ', ' ID ')
Field (' id ', true)//Get all fields except ID
$arr = $m->order (' id ' = ' desc ')->limit (Ten)->field (' username as Name,id ')->select ();
5.table
6.group
7.having
thinkphp Framework Model coherent operation (eight)