yii2 orwhere andwhere的复杂写法

栏目: PHP · 发布时间: 6年前

内容简介:yii2 orwhere andwhere的复杂写法

如果仅仅是多个orwhere条件,其实就是默认的andWhere和orWhere的标准写法,但如果条件是:

queue_name != '' and ( queue_status = '' or (queue_status ='error' and retry = 0))这样的要求,用Yii AR 就比较难写了。

demo如下:

PHP代码

$files = XXXX::find()  
               ->andWhere(['<>', 'queue_name', ''])  
               ->andWhere(['or',  
                   ['queue_status' => ''],  
                   [  
                       'and',  
                       ['queue_status' =>'error'],  
                       ['retry' => 0]  
                   ]  
               ])  
               ->all();  

其实也就这样了。。

重点:

1、不等于的写法

2、或条件其实不是用orWhere,而是用andWhere

3、如果orWhere条件中有双重条件,得使用数组,并使用and进行连接

BTW:今天是PHPcon的第一天,然而我却没空去。我是陪读的书童~~~

本站采用版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"

", 保留原始链接, 此外还必须标注原文标题和链接.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Node.js in Action

Node.js in Action

Mike Cantelon、Marc Harter、TJ Holowaychuk、Nathan Rajlich / Manning Publications / 2013-11-25 / USD 44.99

* Simplifies web application development * Outlines valuable online resources * Teaches Node.js from the ground up Node.js is an elegant server-side JavaScript development environment perfect for scal......一起来看看 《Node.js in Action》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具