: This article mainly introduces the thinkPHP query method summary. if you are interested in the PHP Tutorial, please refer to it. This example summarizes the thinkPHP query method. We will share this with you for your reference. The details are as follows:
I. common query method
1. query using strings;
The code is as follows:
$ M-> where ('Id = 1 and name = "roge" ')-> find ();
This method has the disadvantage that when the query field in the data table is a string, quotation marks must be added to the field value.
2. use arrays (recommended)
$ Data ['name'] = "adfa"; $ data ['id'] = 3; $ data ['_ logical'] = "or "; // logical relationship between Fields. the default value is "and". $ m-> where ($ data)-> find ();
II. expression query
EQ equals;
NEQ is not equal;
GT>;
EGT is greater than or equal;
LT is less;
ELT is less than or equal;
LIKE fuzzy query;
$ Data ['id'] = array ('GT ', 6); $ data ['name'] = array ('like',' % as % '); // notlike // $ data ['name'] = array ('like', array ('% as %', '% ts'),' and '); the default value is the or RELATIONSHIP. if you use and, you must specify $ m-> where ($ data)-> select (); // for other queries, between, not between (spaces exist between them ), in, not,
III. interval query
$ Data ['id'] = array ('GT ', 5), array ('Lt', 10 )); // the relationship between and is generated by default. // $ data ['id'] = array ('Lt ', 5), array ('GT', 10 ), 'or') $ data ['name'] = array ('like', '% d %'), array ('like', '% e % '), 'gege', 'or'); $ m-> where ($ data)-> select ();
IV. statistical query
Count, max, min, avg, sum
The code is as follows:
$ M-> max ('id ')
V. direct SQL query
$ M = M (); $ result = $ m-> query ("select * from think_user where id> 1 ") // query is mainly used to read data $ result = $ m-> execute ("insert into think_user ('name') values ('dfd ')"); // execute is used to write data.