- 查询语法
- 使用格式
- 表达式
- 几个特殊的
- day:时间区间或天数
- now:当前时间
- start
- end
- contain
- is :
- not :
- eq :等于(=)
- neq: 不等于(<>)
- gt:大于(>)
- egt:大于等于(>=)
- lt:小于(<)
- elt: 小于等于(<=)
- [not] like: 同sql的[not]like
- [not] between :同sql的[not] between
- [not] in: 同sql的[not] in
- [not] null :
- [not] null :
查询语法
使用格式
where('字段名','表达式','查询条件');whereOr('字段名','表达式','查询条件');
表达式
| 表达式 | 含义 |
|---|---|
| eq 、= | 等于 |
| neq 、<> | 不等于 |
| gt 、> | 大于 |
| egt 、>= | 大于等于 |
| lt 、< | 小于 |
| elt 、<= | 小于等于 |
| like | 模糊查询 |
| [not] between | 区间查询 |
| [not] in | in 查询 |
| [not] null | 空 |
几个特殊的
| 表达式 | 含义 |
|---|---|
| day 、= | 时间区间或天数 |
| now | 当前时间 |
| start | 相当于 like xxxx% |
| end | 相当于 like %xxxx |
| contain | 相当于 like %xxxx% |
| is | 如果参数不是数组或数组长度为1 相当于= ,如果数组长度大于1 相当于 in |
| not | 如果参数不是数组或数组长度为1 相当于! = ,如果数组长度大于1 相当于not in |
用法示例如下:先说几个特殊的
day:时间区间或天数
//第1中使用//表示create_time>最近两天的where('create_time','day',2);等于$time=strtotime(date("Y-m-d",time()));$time=$time-$day*24*60*60;where('create_time',>,time)//第二种使用//使用时间区间where('create_time','day',['2017-11-09','2017-12-10']);这用使用在后台的查询最近几天的+时间区间的检索中使用比较多
now:当前时间
//创建时间小于当前时间的where('create_time','<','now');
问:为什么使用now 而不使用 where('create_time','<',time())?答:有时查询是需要使用缓存的 而 time() 每次都会变缓存是无效的,使用时根据实际情况注意缓存的有效性
start
where('name','start','rap');相当于where('name','like','rap%');
end
where('name','end','rap');相当于where('name','like','%rap');
contain
where('name','contain','rap');相当于where('name','like','%rap%');
is :
where('title','is',[1,2]);相当于where('title','in',[1,2]);where('name','is',[1]);相当于where('title','=',1);where('title','is',1);相当于where('name','=',1);
not :
where('title','not',[1,2]);相当于where('title','not in',[1,2]);where('name','not',[1]);相当于where('title','!=',1);where('name','not',1);相当于where('name','=',1);
eq :等于(=)
where('id','eq',1);where('id','=',1);where('id',1);
neq: 不等于(<>)
where('id','neq',1);where('id','<>',1);
gt:大于(>)
where('id','gt',1);where('id','>',1);
egt:大于等于(>=)
where('id','egt',1);where('id','>=',1);
lt:小于(<)
where('id','lt',1);where('id','<',1);
elt: 小于等于(<=)
where('id','elt',1);where('id','<=',1);
[not] like: 同sql的[not]like
where('name','like','rap%');
[not] between :同sql的[not] between
where('id','between',[1,8]);where('id','between','1,8');
[not] in: 同sql的[not] in
where('id','in',[1,5,8]);
[not] null :
where('title','null');where('name','not null');
上一篇:基础使用 下一篇:查询操作
