thinkphp Query Method Summary _php instance

Source: Internet
Author: User
This paper summarizes the thinkphp query method. Share to everyone for your reference, as follows:

First, the general Query method

1. Use string queries;
Copy the code as follows: $m->where (' id=1 and Name= ' Roge ')->find ();
One drawback of this approach is that when a query field in a datasheet is a string, quotation marks are added to the field values.

2. How to use arrays (recommended)

$data [' name ']= ' ADFA '; $data [' id ']=3; $data [' _logic ']= ' or '; The logical relationship between fields, by default, and the relationship between $m->where ($data)->find ();

Second, expression query

EQ equals;
NEQ is not equal to;
GT greater than;
EGT is greater than or equal to;
LT is less than;
ELT less than equals;
Like fuzzy query;

$data [' id ']=array (' GT ', 6); $data [' Name ']=array (' like ', '%as% '); notlike//$data [' Name ']=array (' like ', Array ('%as% ', '%ts '), ' and '); The default is an or relationship, if you need to explicitly specify $m->where ($data)->select (),//other query between, not between (there are spaces between them), in,not between,

Third, interval query

$data [' ID ']=array (Array (' GT ', 5), array (' LT ', 10)); The default generation is the relationship of and/$data [' ID ']=array (' lt ', 5), Array (' GT ', ' ten '), ' or ') $data [' Name ']=array (' like ', '%d% '), Array (' Like ', '%e% '), ' gege ', ' or '), $m->where ($data)->select ();

Iv. Statistical Enquiry

Count,max, Min, avg, sum
Copy the Code code as follows: $m->max (' id ')
Five, SQL direct query

$m =m (); $result = $m->query ("select * from Think_user where id>1")//query is primarily used to read data $result= $m->execute (" Insert into Think_user (' name ') VALUES (' DFD ') ");//execute for writing data

Read more about thinkphp for more information on this site: "thinkphp Introductory Course" and "thinkphp Common methods Summary"

It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

  • Related Article

    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.