[TOC]
### 使用格式
~~~
where('字段名','表达式','查询条件');
whereOr('字段名','表达式','查询条件');
~~~
### 表达式
| 表达式 | 含义 |
| --- | --- |
| eq 、= |等于 |
| neq 、<> | 不等于 |
| gt 、> |大于 |
| egt 、>= | 大于等于 |
| lt 、< | 小于 |
| elt 、<= | 小于等于 |
| like | 模糊查询 |
| [not] between | 区间查询 |
| [not] in | in 查询 |
| [not] null |空 |
### 几个特殊的
| 表达式 | 含义 |
| --- | --- |
| sql | 自定义 sql |
| day 、= |时间区间或天数 |
|now | 当前时间 |
| start | 相当于 like xxxx% |
| end | 相当于 like %xxxx |
| contain | 相当于 like %xxxx% |
| is | 如果参数不是数组或数组长度为1 相当于= ,如果数组长度大于1 相当于 in |
| not | 如果参数不是数组或数组长度为1 相当于! = ,如果数组长度大于1 相当于not in|
用法示例如下:
先说几个特殊的
#### sql:自定义 sql
~~~
where('a=? and b=?','sql',[1,'2']); //记得使用? 做预编译 ,防止 sql 注入
whereOr('a=? and b=?','sql',[1,'2']); //记得使用? 做预编译 ,防止 sql 注入
等于
sql('a=? and b=?',[1,2])
sqlOr('a=? and b=?',[1,2])
~~~
#### 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');
~~~
- 序言
- 开始
- 安装 RapPhp
- 应用目录
- 配置文件
- 入口类
- MVC架构
- 控制器基础
- 前置方法
- 拦截器
- 动态路由
- Request和Response
- Cookie和Session
- 模板引擎
- 请求缓存
- 流程图
- 数据库
- 基础使用
- 查询语法
- 查询操作
- where
- order
- limit
- lock
- fields
- join
- distinct
- having
- group
- force
- 查询方法
- 多数据源
- 数据库类型
- Record模型
- 使用Record
- 增删改
- 查找方法
- 数据类型
- 基本类型
- JSON 数据类型
- time
- date
- attach
- const
- 迭代操作
- record 更多方法
- 注入与转json
- 多级缓存
- 多数据源
- 模型生成
- 回调事件
- IOC控制反转
- Ioc基础概念
- 依赖注入
- Scope作用域
- 构造器
- 循环依赖
- AOP面向切面
- AOP使用
- 切面
- AopBuild
- 生成 aop 文件
- 事件勾子
- 执行循序
- Swoole
- Http服务器
- 用户进程
- Context上下文(重要)
- 协程
- 特色功能
- 限流器
- 连接池
- 数据库连接池
- Redis 连接池
- 通用连接池
- Rpc 远程调用
- Rpc服务提供方
- Rpc客户端
- 熔断器与服务降级
- Redis 分布式锁
- 其他功能
- 缓存
- redis
- 文件存储
- 存储简介
- 本地存储
- OSS存储
- 配置
- 日志
- 验证器
- FileUtil
- 数组Util
- Http工具
- 多语言
- 命令行
- 使用命令行
- 生成模型文件
- AOP动态文件生成
- swoole_http服务器
- 自定义命令行
- 异常与调试
- 异常抛出
- 异常处理
- 部署
- URL重写
- DOCKER 镜像(重要)
- 附录
- 回调事件
- 开发规范
- Swoole开发注意点
- 热点行更新排队机制
