where 常用条件范例
Sets the WHERE part of the query.
The method requires a $condition parameter, and optionally a $params parameter specifying the values to be bound to the query.
The $condition parameter should be either a string (e.g. 'id=1') or an array.
The $condition specified as an array can be in one of the following two formats:
- hash format:
['column1' => value1, 'column2' => value2, ...] - operator format:
[operator, operand1, operand2, ...]
A condition in hash format represents the following SQL expression in general: column1=value1 AND column2=value2 AND .... In case when a value is an array, an IN expression will be generated. And if a value is null, IS NULL will be used in the generated expression. Below are some examples:
['type' => 1, 'status' => 2]generates(type = 1) AND (status = 2).['id' => [1, 2, 3], 'status' => 2]generates(id IN (1, 2, 3)) AND (status = 2).['status' => null]generatesstatus IS NULL.
A condition in operator format generates the SQL expression according to the specified operator, which can be one of the followings:
and: the operands should be concatenated together using
AND. For example,['and', 'id=1', 'id=2']will generateid=1 AND id=2. If an operand is an array, it will be converted into a string using the rules described here. For example,['and', 'type=1', ['or', 'id=1', 'id=2']]will generatetype=1 AND (id=1 OR id=2). The method will not do any quoting or escaping.or: similar to the
andoperator except that the operands are concatenated usingOR. For example,['or', ['type' => [7, 8, 9]], ['id' => [1, 2, 3]]will generate(type IN (7, 8, 9) OR (id IN (1, 2, 3))).not: this will take only one operand and build the negation of it by prefixing the query string with
NOT. For example['not', ['attribute' => null]]will result in the conditionNOT (attribute IS NULL).between: operand 1 should be the column name, and operand 2 and 3 should be the starting and ending values of the range that the column is in. For example,
['between', 'id', 1, 10]will generateid BETWEEN 1 AND 10.not between: similar to
betweenexcept theBETWEENis replaced withNOT BETWEENin the generated condition.in: operand 1 should be a column or DB expression, and operand 2 be an array representing the range of the values that the column or DB expression should be in. For example,
['in', 'id', [1, 2, 3]]will generateid IN (1, 2, 3). The method will properly quote the column name and escape values in the range.To create a composite
INcondition you can use and array for the column name and value, where the values are indexed by the column name:['in', ['id', 'name'], [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']] ].You may also specify a sub-query that is used to get the values for the
IN-condition:['in', 'user_id', (new Query())->select('id')->from('users')->where(['active' => 1])]not in: similar to the
inoperator except thatINis replaced withNOT INin the generated condition.like: operand 1 should be a column or DB expression, and operand 2 be a string or an array representing the values that the column or DB expression should be like. For example,
['like', 'name', 'tester']will generatename LIKE '%tester%'. When the value range is given as an array, multipleLIKEpredicates will be generated and concatenated usingAND. For example,['like', 'name', ['test', 'sample']]will generatename LIKE '%test%' AND name LIKE '%sample%'. The method will properly quote the column name and escape special characters in the values. Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operandfalseto do so. For example,['like', 'name', '%tester', false]will generatename LIKE '%tester'.or like: similar to the
likeoperator except thatORis used to concatenate theLIKEpredicates when operand 2 is an array.not like: similar to the
likeoperator except thatLIKEis replaced withNOT LIKEin the generated condition.or not like: similar to the
not likeoperator except thatORis used to concatenate theNOT LIKEpredicates.exists: operand 1 is a query object that used to build an
EXISTScondition. For example['exists', (new Query())->select('id')->from('users')->where(['active' => 1])]will result in the following SQL expression:EXISTS (SELECT "id" FROM "users" WHERE "active"=1).not exists: similar to the
existsoperator except thatEXISTSis replaced withNOT EXISTSin the generated condition.Additionally you can specify arbitrary operators as follows: A condition of
['>=', 'id', 10]will result in the following SQL expression:id >= 10.
where 常用条件范例的更多相关文章
- NSDate常用代码范例
NSDate常用代码范例 NSDate类用于保存时间值,同时提供了一些方法来处理一些基于秒级别时差(Time Interval)运算和日期之间的早晚比较等. 1. 创建或初始化可用以下方法 用于创建N ...
- SQL常用条件操作符
1.SQL的六类内容: (1)数据定义语言(DDL): 创建.删除表结构的语句,包括Create.Drop (2)数据控制语言(DCL): 为定义数据访问及修改权限而实现的语句,包括Grant.Rev ...
- 针对主流浏览器的CSS-HACK写法及IE常用条件注释
一.通用区分方式: IE6.IE7能识别*,标准浏览器(如FF)不能识别*:IE6能识别*,但不能识别 !important:IE7能识别*,也能识别 !important:IE8能识别\0,不能识别 ...
- SQL语句 常用条件判断
条件判断写法: 对每天记录执行操作时,判断所限制的条件-----> 操作符: = <>(不匹配检查) != &l ...
- Linux的iptables常用配置范例(1)
以下是来自 http://wiki.ubuntu.org.cn/IptablesHowTo 上的配置说明 可以通过/sbin/iptables -F清除所有规则来暂时停止防火墙: (警告:这只适合在没 ...
- shell中的常用条件判断
-e :该“文件名”是否存在.exit-d :该文件名是否为目录.dir-f :该文件名是否为普通文件.file -b:该文件是否为块文件.block -r :该文件是否具有可读属性 read-w ...
- Linux的iptables常用配置范例(2)
iptables -F #清除所有规则 iptables -X #清除所有自定义规则 iptables -Z #各项计数归零 iptables -P INPUT DROP #将input链 ...
- Linux的iptables常用配置范例(3)
编辑/etc/rc.local,加入iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE,外网口eth1为dhc ...
- IOS正则表达式 (身份证、电话、汉字等常用条件筛选)
下面的正则列表 替换对应的正则规则 那个字符串就可以了 例如: //正则规则 NSString *regex = @"^((13[0-9])|(147)|(17[0-9])|(15[^ ...
随机推荐
- python--多线程多进程
一.进程 对于操作系统来说,一个任务就是一个进程(Process),比如打开一个浏览器就是启动一个浏览器进程,打开一个记事本就启动了一个记事本进程,打开两个记事本就启动了两个记事本进程.进程是很多资源 ...
- VS2015+VisualSVN+TortoiseSVN安装及使用
1. SVN 是什么 SVN 是 Apache Subversion 的缩写,是一个开放源代码的版本控制系.这些数据放置在一个中央资料档案库(repository) 中. 这个档案库很像一个普通的文件 ...
- react 入坑之罪
componentDidMount :生命周期在react下只调用一次, render:比它先执行 componentWillRecvieProps(newProps) :能取到父组件的值 rende ...
- Kostya Keygen#2分析
主要就是构造408ede处的2A个字节.. 其中第一个字节必须为0x2D,倒数第二个字节必须为0x36,倒数第三个字节为0x31. 之后,对这个2A字节的缓冲区,要满足一些条件: 1\ 在408ede ...
- git冲突解决的几种办法
文章目录 git stash 栈 放弃本地修改 撤销分支 强行冲掉之前的分支 删除分支 git stash 栈 git stash git pull git stash pop 当pull出现冲突时 ...
- 微信小程序上传图片
话不多说,直接上码. <view class="section"> <!--放一张图片或按钮 点击时去选择图片--> <image class='ph ...
- ECharts柱状图
首先我们要先去Echarts 官网 根据自己需要的版本进行下载下载 下载完成后,我们在项目中引入echarts 随后创建容器来存放我们要添加的柱状图 容器创建完毕我们需要在js中设置他的属性和值 此配 ...
- mysql插入中文报错的问题
报错:1366, "Incorrect string value: '\\xE6\\xB7\\xB1\\xE5\\x85\\xA5...' for column ' 由于公司原因之前一直在使 ...
- 深入java----垃圾回收
Java和C++之间有一睹内存动态分配和垃圾收集技术所围成的“高墙”,墙外面的人想进去,墙里面的人想出来.-------<深入理解JVM虚拟机> 补充:在无用对象判断这两种方法中,都是靠对 ...
- 非关系统型数据库-mangodb
第三十六课 非关系统型数据库-mangodb 目录 二十四 mongodb介绍 二十五 mongodb安装 二十六 连接mongodb 二十七 mongodb用户管理 二十八 mongodb创建集合. ...