Thinkphp interval query, statistical query, and SQL direct query

Source: Internet
Author: User
Interval query $ data [& amp; #39; id & amp; #39;] array (& amp; #39; gt & amp; #39;, 4 ), array (& amp; #39; lt & amp; #39;, 10); // The default relationship is (and) and the link // SELECT * FROM 'TP _ user' W...

Interval query

  1. $ Data ['id'] = array ('GT ', 4), array ('Lt', 10); // The default relationship is (and) and
  2. // SELECT * FROM 'TP _ user' WHERE ('id'> 4) AND ('id' <10 ))
  3.  
  4. $ Data ['id'] = array ('GT ', 4), array ('Lt', 10), 'OR') // The link is (or) or relationship
  5.  
  6. $ Data ['name'] = array ('like', '% 100'), array ('like',' %

% '), 'Gege',' or ');Multiple arrays can be added to the array. if there is no or, the relationship is "and" by default.

Statistics Query

  1. Count // Obtain the number
  2. Max // obtain the maximum number
  3. Min // obtain the minimum number
  4. Avg // Obtain the average
  5. Sum // get the sum
  6. $ M = M ('user ');
  7. $ Arr = $ m-> count (); // obtain the total number of users.
  8. $ Arr = $ m-> where ("username = 'gege'")-> count (); // place the string
  9.  
  10. $ M = M ('user ');
  11. $ Data ['username'] = 'gege'; // place an array
  12. $ C = $ m-> where ($ data)-> count (); // The array operation is more standard.
You can use SQL to directly query and perform more operations flexibly.

A. The primary number of queries processes the data read. The result set is returned successfully. if the query fails, the return value is boolean false.

  1. $ M = M ();
  2. $ Result = $ m-> query ("select * from tp_user where id> 50 ");
  3. Var_dump ($ result );

B. execute is used to update write operations. if a write operation is successful, the number of affected rows is returned. if a write operation fails, the return value is boolean false.

  1. $ M = M ();
  2. $ Result = $ m-> execute ("insert into tp_user ('Username') values ('ztz3 ')");
  3. Var_dump ($ result );

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.