This paper illustrates the thinkphp interval query, statistical query and SQL direct query. Share to everyone for your reference. The specific methods are as follows:
First, the interval query:
Copy Code code as follows:
$data [' ID ']=array (Array (' GT ', 4), array (' LT ', 10);/The default relationship is (and) and the relationship
SELECT * from ' Tp_user ' WHERE ((' ID ' > 4) and (' ID ' < 10))
$data [' ID ']=array (Array (' GT ', 4), array (' LT ', ten), ' or ')//relationship is (or) or relationship
$data [' Name ']=array (' like ', '%2% '], array (' like ', '%% '), ' gege ', ' or ');
Multiple arrays can be added to an array, and if there is no or, the default is an and relationship
Second, the statistical inquiry:
Count//Get number
Max//Get maximum number
Min//Get minimum number
AVG//Get average
Sum//Get sum
Copy Code code as follows:
$m =m (' User ');
$arr = $m->count ()//total number of users
$arr = $m->where ("Username= ' Gege '")->count (); Place string
$m =m (' User ');
$data [' username ']= ' gege ';//place array
$c = $m->where ($data)->count (); Array Operations Compare specifications
three, SQL direct query , very flexible can do more operations.
A, query main number processing read data, successfully returned the result set of data, failed to return Boolean false
Copy Code code as follows:
$m =m ();
$result = $m->query ("select * from Tp_user where ID >50");
Var_dump ($result);
B, execute is used to update a write operation, successfully return the number of affected rows, and fail to return Boolean false
Copy Code code as follows:
$m =m ();
$result = $m->execute ("INSERT into Tp_user (' username ') VALUES (' ztz3 ')");
Var_dump ($result);
I hope this article will be helpful to everyone's thinkphp framework program design.