ThinkPHP query method summary

Source: Internet
Author: User
: This article mainly introduces the thinkPHP query method summary. if you are interested in the PHP Tutorial, please refer to it. This example summarizes the thinkPHP query method. We will share this with you for your reference. The details are as follows:

I. common query method

1. query using strings;

The code is as follows:

$ M-> where ('Id = 1 and name = "roge" ')-> find ();


This method has the disadvantage that when the query field in the data table is a string, quotation marks must be added to the field value.

2. use arrays (recommended)

$ Data ['name'] = "adfa"; $ data ['id'] = 3; $ data ['_ logical'] = "or "; // logical relationship between Fields. the default value is "and". $ m-> where ($ data)-> find ();

II. expression query

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

$ Data ['id'] = array ('GT ', 6); $ data ['name'] = array ('like',' % as % '); // notlike // $ data ['name'] = array ('like', array ('% as %', '% ts'),' and '); the default value is the or RELATIONSHIP. if you use and, you must specify $ m-> where ($ data)-> select (); // for other queries, between, not between (spaces exist between them ), in, not,

III. interval query

$ Data ['id'] = array ('GT ', 5), array ('Lt', 10 )); // the relationship between and is generated by default. // $ data ['id'] = array ('Lt ', 5), array ('GT', 10 ), 'or') $ data ['name'] = array ('like', '% d %'), array ('like', '% e % '), 'gege', 'or'); $ m-> where ($ data)-> select ();

IV. statistical query

Count, max, min, avg, sum

The code is as follows:

$ M-> max ('id ')


V. direct SQL query

$ M = M (); $ result = $ m-> query ("select * from think_user where id> 1 ") // query is mainly used to read data $ result = $ m-> execute ("insert into think_user ('name') values ('dfd ')"); // execute is used to write data.

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.