This article mainly introduces thinkphp common queries and expression queries, and analyzes in detail the usage of common queries and expression queries in thinkphp in the form of examples, it contains the string and array modes of common queries and various common techniques in expression queries. This article describes thinkphp common queries and expression queries. Share it with you for your reference. The specific analysis is as follows:
I. common query method
A. string mode:
The code is as follows:
$ Arr = $ m-> where ("sex = 0 and username = 'give'")-> find (); // enclose the string with quotation marks.
B. array mode:
The code is as follows:
$ Data ['sex'] = 0;
$ Data ['username'] = 'gege ';
$ Arr = $ m-> where ($ data)-> find (); // transmits the previous array for query. this method defaults to the and (and) relationship.
Note: If the or relationship is used, you need to add an array value.
The code is as follows:
$ Data ['sex'] = 0;
$ Data ['username'] = 'gege ';
$ Data ['_ logic'] = 'or'; // add a _ logic value to the array as an or relationship.
II. expression query method
The code is as follows:
$ Data ['id'] = array ('Lt ', 6); // the array element is still an array
$ Arr = $ m-> where ($ data)-> select ();
/*
EQ = // case insensitive
NEQ is not equal
GT>
EGT greater than or equal
LT is less
ELT less than or equal
LIKE fuzzy query */
$ Data ['username'] = array ('like', '% ge %'); // like
$ Arr = $ m-> where ($ data)-> select (); // All records containing ge are queried.
// NOTLIKE does not contain
$ Data ['username'] = array ('notlike', '% ge %'); // There is no space in the notlike Center
$ Arr = $ m-> where ($ data)-> select ();
// Note: If a field needs to match multiple wildcards
$ Data ['username'] = array ('like', array ('% ge %', '% 100',' % 5% '),' and '); // if there is no third value and, the default relationship is or.
$ Arr = $ m-> where ($ data)-> select (); // or (or) you can find one of the values.
//
$ Data ['id'] = array ('between', array (5, 7 ));
$ Arr = $ m-> where ($ data)-> select ();
// SELECT * FROM 'TP _ user' WHERE ('id' BETWEEN 5 AND 7 ))
$ Data ['id'] = array ('not between', array (5, 7); // note that spaces must exist between not and.
$ Arr = $ m-> where ($ data)-> select ();
// IN
$ Data ['id'] = array ('in', array (4,6, 7 ));
$ Arr = $ m-> where ($ data)-> select ();
// SELECT * FROM 'TP _ user' WHERE ('id' IN (4,6, 7 ))
$ Data ['id'] = array ('not in', array (, 7 ));
$ Arr = $ m-> where ($ data)-> select ();
// SELECT * FROM 'TP _ user' WHERE ('id' not in (4,6, 7 ))
I hope this article will help you with thinkphp framework programming.