thinkphp interval query, statistic Query and SQL Direct query instance Analysis _php instance

Source: Internet
Author: User

This paper illustrates the thinkphp interval query, statistical query and SQL direct query. Share to everyone for your reference. The specific methods are as follows:

First, the interval query:

Copy Code code as follows:
$data [' ID ']=array (Array (' GT ', 4), array (' LT ', 10);/The default relationship is (and) and the relationship
SELECT * from ' Tp_user ' WHERE ((' ID ' > 4) and (' ID ' < 10))

$data [' ID ']=array (Array (' GT ', 4), array (' LT ', ten), ' or ')//relationship is (or) or relationship

$data [' Name ']=array (' like ', '%2% '], array (' like ', '%% '), ' gege ', ' or ');

Multiple arrays can be added to an array, and if there is no or, the default is an and relationship

Second, the statistical inquiry:

Count//Get number
Max//Get maximum number
Min//Get minimum number
AVG//Get average
Sum//Get sum

Copy Code code as follows:
$m =m (' User ');
$arr = $m->count ()//total number of users
$arr = $m->where ("Username= ' Gege '")->count (); Place string

$m =m (' User ');
$data [' username ']= ' gege ';//place array
$c = $m->where ($data)->count (); Array Operations Compare specifications

three, SQL direct query , very flexible can do more operations.

A, query main number processing read data, successfully returned the result set of data, failed to return Boolean false

Copy Code code as follows:
$m =m ();
$result = $m->query ("select * from Tp_user where ID >50");
Var_dump ($result);

B, execute is used to update a write operation, successfully return the number of affected rows, and fail to return Boolean false
Copy Code code as follows:
$m =m ();
$result = $m->execute ("INSERT into Tp_user (' username ') VALUES (' ztz3 ')");
Var_dump ($result);

I hope this article will be helpful to everyone's thinkphp framework program design.

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.