Yii的where方法使用大全
来源:互联网 发布:jackson json忽略空值 编辑:程序博客网 时间:2024/05/18 03:08
1)简单的赋值
- ->where("id=:id", [
- 'id' => 1
- ])
上面的程式等同于 id=1
2)AND查询
- ->where("id=:id and pack_name=:pack_name", [
- ':id' => 1,
- ':pack_name' => 'com.famigo.sandbox'
- ])
或者
- ->where([
- 'and',
- 'id=:id',
- 'pack_name=:pack_name'
- ], [
- ':id' => 1,
- ':pack_name' => 'com.famigo.sandbox'
- ])
3)OR查询
- ->where("id=:id or pack_name=:pack_name", [
- ':id' => 1,
- ':pack_name' => 'com.famigo.sandbox'
- ])
- ->where([
- 'or',
- 'id=:id',
- 'pack_name=:pack_name'
- ], [
- ':id' => 1,
- ':pack_name' => 'com.famigo.sandbox'
- ])
4)AND OR 混合查询
- ->where([
- 'and',
- 'display=:display',
- [
- 'or',
- 'id=:id1',
- 'id=:id2'
- ]
- ], [
- ':display' => 1,
- ':id1' => 1,
- ':id2' => 2
- ])
5)IN查询
- ->where([
- 'in', 'id', [1, 3, 5, 6]
- ])
- ->where([
- 'and',
- 'display=:display',
- 'lang=:lang',
- [
- 'in', 'id', [1, 3, 5, 6]
- ]
- ], [
- ':display' => 1,
- ':lang' => 2
- ])
更为麻烦点的例子
- ->where([
- 'or',
- [
- 'and',
- 'display=:display1',
- [
- 'in', 'id', [1, 3, 5, 6]
- ]
- ],
- [
- 'and',
- 'display=:display2',
- [
- 'in', 'id', [2, 4, 8, 9]
- ]
- ]
- ], [
- ':display1' => 1,
- ':display2' => 2,
- ])
6)NOT IN 查询
- ->where([
- 'not in', 'id', [1, 2, 4, 3]
- ])
复杂的使用方法和上述的IN是一样的,参考即可。
7)LIKE 查询
- ->where([
- 'like', 'pack_name', '%sandbox%'
- ])
- ->where([
- 'like', 'pack_name', [
- '%sandbox%',
- 'com.famigo%'
- ]
- ])
上面程式等同于`pack_name` LIKE '%sandbox%' AND `pack_name` LIKE 'com.famigo%'
- ->where([
- 'or like', 'pack_name', [
- '%sandbox%',
- 'com.famigo%'
- ]
- ])
- ->where([
- 'or not like', 'pack_name', [
- '%sandbox%',
- 'com.famigo%'
- ]
- ])
- ->where([
- 'not like', 'pack_name', [
- '%sandbox%',
- 'com.famigo%'
- ]
- ])
0 0
- Yii的where方法使用大全
- Yii的where方法使用大全
- Yii的where方法使用大全
- Yii中where方法使用
- Yii2的where方法使用大全
- yii使用SESSION的方法
- yii使用cookie的方法
- YII使用ckeditor的方法
- thinkphp的where方法的使用
- ThinkPHP中where()方法的使用
- Yii框架下的where条件查询
- yii的relations方法的使用
- yii的relations方法的使用
- yii的relations方法的使用
- Yii的relations方法的使用
- yii的relations方法的使用
- yii的relations方法的使用
- yii 中RULES方法的使用
- PostgreSQL和MySQL的性能对比实验
- Mina框架详解
- ElasticSearch教程(二)——ElasticSearch基本插件head
- 易语言学习第二十一课----动态数组使用1
- Linux系统resolv.conf配置信息丢失的解决方法
- Yii的where方法使用大全
- SQL语句Left join 中On和Where的用法区别
- NBUT 1463 内部收益率 二分
- Sevlet的生命周期
- JEEWX微信企业号管家,开源免费,1.0版本发布
- PRAGMA AUTONOMOUS_TRANSACTION(自治事务)
- solr更新schema.xml后,重新把配置文件注入到zookeeper
- FZU 2125 简单的等式
- ios基础知识整理1