yii2 orwhere andwhere的复杂写法

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

内容简介: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的第一天,然而我却没空去。我是陪读的书童~~~

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

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


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

查看所有标签

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

Algorithms in Java, Part 5

Algorithms in Java, Part 5

Robert Sedgewick / Addison-Wesley Professional / 2003-7-25 / USD 54.99

Algorithms in Java, Third Edition, Part 5: Graph Algorithms is the second book in Sedgewick's thoroughly revised and rewritten series. The first book, Parts 1-4, addresses fundamental algorithms, data......一起来看看 《Algorithms in Java, Part 5》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

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

HEX CMYK 互转工具