thinkphp Review (d) Inquiry method in-depth study

Source: Internet
Author: User

The main query methods are: Expression query, fuzzy query, between statement, in statement, interval query, statistical data, ordinary way query, but most of them just introduced arrays, understand the first, the other is almost all clear, the only thing to note is in the background notlike no spaces in the middle, and not in , Not between must have a space in the middle to be effective, do not mix with the foreground label behind, words not to say, directly on the code

Public Function Showone () {

echo "Welcome". $_get[' name '];//can be index/show/name/yjs directly on the page

General use of query methods

/*

* 1. Expression query

* Greater than GT, less than LT, equals EQ, greater than or equal to GEQ, less than or equal to Leq, not equal to NEQ constant equals Heq!== is Nheq

$m =m (' User ');

$data [' id ']=array (' GT ', ' 2 ');

$arr = $m->where ($data)->select ();

Var_dump ($arr);

$this->display ();

* That is, you can assign a where condition in the form of an array , which is an ID greater than 2

*/

/*

* 2. Fuzzy query notlike can not have spaces in the middle, but not between the last middle must have spaces

$m =m (' User ');

$data [' username ']=array (' notlike ', Array ('%ge% ', '%2% '), ' and ');

$arr = $m->where ($data)->select ();

Var_dump ($arr);

$this->display ();

* That is, the contents of the query inside the array must be consistent, and because it is notlike, so long as not both of the contents are output

*/

/*

* 2.between statement not between must have a space in the middle;

$m =m (' User ');

$data [' id ']=array (' Not between ', Array (5,7));

$arr = $m->where ($data)->select ();

Var_dump ($arr);

$this->display ();

* As long as it's not 5-7 between the output

*/

/*

* 2.in statement does not have a space in the middle;

$m =m (' User ');

$data [' id ']=array (' Not in ', Array (5,7,8));

$arr = $m->where ($data)->select ();

Var_dump ($arr);

$this->display ();

* As long as the contents of the ID not 5,7,8 three are output

*/

/*

* Interval Query

$m =m (' User ');

$data [' ID ']=array (Array (' GT ', 1), Array (' LT ', 8));//two arrays default to and, which is to find data between 1 and 8

$data [' ID ']=array (array (' LT ', 4), Array (' GT ', 8), ' or ');

Here Array (array (), array ());

and array (' Like ', Array ('%ge% ', '%2% ')); default is OR

$arr = $m->where ($data)->select ();

$this->assign (' id ', $arr);

Var_dump ($arr);

$this->display ();

*/

/*

* Statistical data

$m =m (' User ');

$data [' id ']=array (' lt ', 8);

$count = $m->where ($data)->count ();

Var_dump ($arr);

$this->display ();

*/

/* Ask Max Max

* min min

* Average AVG

* Sum sum

$m =m (' User ');

$maxid = $m->max (' id ');

Echo $maxid;

$count = $m->where ($data)->count ();

Var_dump ($arr);

$this->display ();

* Other methods are the same

*/

/*

* Normal mode query

* query (); Processing of read data ( query )

* Execute (); Update write operation

$m =m ();

$arr = $m->query ("select * from Tp_user where id>5");

Successful return result set, Failure returns Boolean false

Var_dump ($arr);

*/

/*

* Execute (); Update write operation ( update )

*

$m =m ();

$arr = $m->execute ("INSERT into Tp_user (' username ', ' sex ') VALUES (' DC ', ' 0 ')");

Successful return affects number of rows, Failure returns Boolean false

Var_dump ($arr);

*/

}

}

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.