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[^ ...
随机推荐
- 简易OA漫谈之工作流设计(五,直接上级)
规则引擎里比较复杂的问题就是:配置步骤的审批人. 某一个步骤由谁来审批,有很多复杂情况: 1.指定某一个具体的人.这种通常用于一些特殊的岗位,全公司只有一个,比如小公司里的财务,人事专员等. 2.指定 ...
- 维修数列 Splay(这可能是我写过最麻烦的题之一了。。。用平衡树维护dp。。。丧心病狂啊。。。。)
题目来源BZOJ1500 这题的思路: 1.这题的话,稍微会splay的人,一般前面四个都不是问题..主要是最后的一个,要你在修改的同时要维护好最大字段和... 2.最大字段和其实就是区间合并.具体操 ...
- raid卡的结构示意图
raid卡的结构示意图,取自<大话存储>第124页 ROM:一般用FLash芯片做ROM,存放着初始化RAID卡必须的代码以及实现RAID功能所需的代码; XOR芯片:专门用来做RAID ...
- 浏览器与WEB服务器交互
问题:打开浏览器,在地址栏输入url到页面展现,整个过程发生了什么? 图示: 步骤: 1 用户输入网址,包括协议和域名. 2 浏览器先查找自身缓存有没有记录,没有的话再找操作系统缓存. 3 当浏览器在 ...
- 常被问到的十个 Java 面试题
在这篇文章中,我试图收录最有趣和最常见的问题.此外,我将为您提供正确的答案. 接下来,就让我们来看看这些问题. 1. 以满分十分来评估自己——你有多擅长 Java? 如果你并不完全确信你自己或是你对 ...
- python之json序列
# from urllib import request## f=request.urlopen("http://123.178.101.29:81/xs_main.aspx?xh=2015 ...
- POJO、JavaBean、DTO的区别
一.POJO(Plain Ordinary Java Object)简单的Java对象,其中有一些属性及其getter setter方法的类,没有业务逻辑(重点理解一下"没有业务逻辑&quo ...
- Linux常见命令快捷方式
命令行编辑的辅助操作: Tab健:自动补齐 Ctrl +U :清空至首行 Ctrl +K: 清空至尾行 Ctrl +L:(或者clear) 清屏 Ctrl +C: 取消执行命令 获取帮助命令: 内 ...
- OTP gen_server
erlang behaviour小结之gen_server OTP入门 分类: Erlang2012-08-06 18:55 867人阅读 评论(0) 收藏 举报 servererlangcallba ...
- [SCOI2003]字符串折叠
一道蛮好玩的区间DP...其实只要做好check...然后统计答案就好了...QAQ... 呆码: #include<iostream> #include<cstdio> #i ...