Basic Query method
String condition query,
Indexed array Condition query
Object condition Query
SQL statements
The case is the same,
However, there is a lowercase to uppercase conversion when executing, so it's best to write uppercase
$condition =new \stdclass ();//Object Form Query
Stdclass is a PHP built-in class that can be understood as an empty class, where you want to save the condition as a field,
The backslash \ is to set the namespace to the root directory, or it will cause the current directory to not find this class.
An expression query
Greater than or equal to
Custom expressions
Format:
$map [' Field name ']=array (' expression ', ' query condition ');
<?php
//This class is automatically generated by the system and is intended for testing purposes only
namespace Home\controller;
UseThink\model;
UseThink\controller;
classIndexcontrollerextendsController {
PublicfunctionIndex () {
//Echo ' <meta content-type=text/html;charset=utf-8/> ';
Echo' <pre> ';
//$user =new Model (' user ');
Var_dump ($user->select ());
$user= M (' User ');
//Var_dump ($user->where (' id=5 and user= cherry Meatballs ')->select ());
$condition [' id ']=5;
$condition [' User ']= ' cherry balls ';
Var_dump ($user->where ($condition)->select ());
The above two conditions are the relationship of and
$condition [' _logic ']= ' or ';
Var_dump ($user->where ($condition)->select ());
$condition=New\stdclass ();//Object Form Query
The preceding backslash indicates a system-supplied lookup STD class
$condition->id = 5;
$condition->user = ' cherry little meatballs ';
$condition->_logic = ' OR ';
Var_dump($user->where ($condition)->select ());
}
PublicfunctionQuery () {
$user= M (' User ');
Echo' <pre> ';
//$map [' id ']=array (' eq ', 5);//Here to Map1 is casual, no rules
$map [' id ']=array (' Neq ', 5);//id Not equal to 5
$map [' id ']=array (' GT ', 5);//id Greater than 5
$map [' id ']=array (' Egt ', 5);//greater than or equal to
$map [' id ']=array (' lt ', 5);//Less than
$map [' id ']=array (' ELT ', 5);//Less than
Fuzzy query, there are three kinds of
$map [' User ']=array (' like ', '% of small ');//First, single condition
$map [' User ']=array (' notlike ', '% of small ');//The second, the case is irrelevant
Note that this isn't like there are no spaces.
Multi-Conditional Fuzzy query
$map [' User ']=array (' like ', array ('% small% ', '% wax% '), ' and ');
Between-interval lookup, from M to n
$map [' id ']=array (' between ', ' 5,7 ');//Find out between 5 and 7 (5 6 7)
$map [' id ']=array (' between ', Array (' 5 ', ' 7 '));//This is another form
Not between-note that the middle four is a space
$map [' id ']=array (' Not between ', ' 5,7 ');
Inch
$map [' id ']=array (' in ', ' 5,6,8 ');
$map [' id ']=array (' in ', Array (' 5 ', ' 7 ', ' 8 '));
Not in
$map [' id ']=array (' not ', ' 5,6,8 ');
$map [' id ']=array (' Not in ', Array (' 5 ', ' 7 ', ' 8 '));
Custom Query-Exp
$map[' ID ']=Array(' exp ', ' = 5 ');
$map[' ID ']=Array(' exp ', ' >10 ');
//to build a complex point
$map[' id '] =Array(
' Exp ',
' = 5 '
);
$map[' user '] =Array(
' Exp ',
' = ' cherry Balls '
);
$map[' _logic '] = ' or ';
Var_dump($user->where ($map)->select ());
}
}
[tp3.2.1]sql query Statement (i)