Common query and expression query of thinkphp

Source: Internet
Author: User
1. common query method a and string: $ arr $ m-& gt; where (& quot; sex0andusername & amp; #39; gege & amp; #39; & quot ;) -& gt; find (); // the string must be enclosed in quotation marks B, array $ data [& amp; #39; sex & amp; #3...

I. common query method

A. string: $ arr = $ m-> where ("sex = 0 and username = 'gege'")-> find (); // enclose the string with quotation marks.

B. array

  1. $ Data ['sex'] = 0;
  2. $ Data ['username'] = 'gege ';
  3. $ 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.

  1. $ Data ['sex'] = 0;
  2. $ Data ['username'] = 'gege ';
  3. $ Data ['_ logic'] = 'or'; // add a _ logic value to the array as an or relationship.

 

II. expression query method

  1. $ Data ['id'] = array ('Lt ', 6); // the array element is still an array
  2. $ Arr = $ m-> where ($ data)-> select ();
  3. EQ = // case insensitive
  4. NEQ is not equal
  5. GT>
  6. EGT greater than or equal
  7. LT is less
  8. ELT less than or equal
  9. LIKE fuzzy query
  10. $ Data ['username'] = array ('like', '% ge %'); // like
  11. $ Arr = $ m-> where ($ data)-> select (); // All records containing ge are queried.
  12. NOTLIKE does not contain
  13. $ Data ['username'] = array ('notlike', '% ge %'); // There is no space in the notlike Center
  14. $ Arr = $ m-> where ($ data)-> select ();
  15.  
  16. Note: If a field matches multiple wildcards
  17. $ Data ['username'] = array ('like', array ('% ge %', '% 100',' % 5% '),' and '); // if there is no third value and, the default relationship is or.
  18. $ Arr = $ m-> where ($ data)-> select (); // or (or) you can find one of the values.
  19.  
  20. BETWEEN
  21. $ Data ['id'] = array ('between', array (5, 7 ));
  22. $ Arr = $ m-> where ($ data)-> select ();
  23. // SELECT * FROM 'TP _ user' WHERE ('id' BETWEEN 5 AND 7 ))
  24. $ Data ['id'] = array ('not between', array (5, 7); // note that spaces must exist between not and.
  25. $ Arr = $ m-> where ($ data)-> select ();
  26. IN
  27. $ Data ['id'] = array ('in', array (4,6, 7 ));
  28. $ Arr = $ m-> where ($ data)-> select ();
  29. // SELECT * FROM 'TP _ user' WHERE ('id' IN (4,6, 7 ))
  30.  
  31. $ Data ['id'] = array ('not in', array (, 7 ));
  32. $ Arr = $ m-> where ($ data)-> select ();
  33. // SELECT * FROM 'TP _ user' WHERE ('id' not in (4,6, 7 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.