This paper summarizes the thinkphp query method. Share to everyone for your reference, as follows:
First, the general Query method
1. Use string queries;
Copy the code as follows: $m->where (' id=1 and Name= ' Roge ')->find ();
One drawback of this approach is that when a query field in a datasheet is a string, quotation marks are added to the field values.
2. How to use arrays (recommended)
$data [' name ']= ' ADFA '; $data [' id ']=3; $data [' _logic ']= ' or '; The logical relationship between fields, by default, and the relationship between $m->where ($data)->find ();
Second, expression query
EQ equals;
NEQ is not equal to;
GT greater than;
EGT is greater than or equal to;
LT is less than;
ELT less than equals;
Like fuzzy query;
$data [' id ']=array (' GT ', 6); $data [' Name ']=array (' like ', '%as% '); notlike//$data [' Name ']=array (' like ', Array ('%as% ', '%ts '), ' and '); The default is an or relationship, if you need to explicitly specify $m->where ($data)->select (),//other query between, not between (there are spaces between them), in,not between,
Third, interval query
$data [' ID ']=array (Array (' GT ', 5), array (' LT ', 10)); The default generation is the relationship of and/$data [' ID ']=array (' lt ', 5), Array (' GT ', ' ten '), ' or ') $data [' Name ']=array (' like ', '%d% '), Array (' Like ', '%e% '), ' gege ', ' or '), $m->where ($data)->select ();
Iv. Statistical Enquiry
Count,max, Min, avg, sum
Copy the Code code as follows: $m->max (' id ')
Five, SQL direct query
$m =m (); $result = $m->query ("select * from Think_user where id>1")//query is primarily used to read data $result= $m->execute (" Insert into Think_user (' name ') VALUES (' DFD ') ");//execute for writing data
Read more about thinkphp for more information on this site: "thinkphp Introductory Course" and "thinkphp Common methods Summary"
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.