连贯操作where用于指定条件,支持字符串和数组两种格式。区别是字符串是原样代入,数组则会根据配置进行值过滤和字段保留字冲突解决。
* * * * *
$model->where('id<10')->select();
$model->where(array('id'=>array('<',10)))->select();
生成的SQL语句:
select * from table where id<10
* * * * *
$model->where('id in (1,2,3)')->select();
$model->where(array('id'=>array('in',array(1,2,3))))->select();
上面两句话等同。
生成的SQL语句:
select * from table where id in (1,2,3)
* * * * *
$model->where("(age>80 or age<10) and city='无锡'")->select();
$m->where(
array(
'and'=>array(
'age'=>array('>',80),
'or'=>array(
'age'=>array('<',10)
)
)
,'city'=>'无锡'
)
)
->select();
上面两句话等同。
生成的SQL语句:
select * from table where (age > 80 or age < 10) and city='无锡'
* * * * *
$model->where('address'=>array('like'=>'%无锡%'));
$model->where('birthday'=>array('>=','1970-01-01'));
$model->select();
生成的SQL语句:`select * from table where address like '%无锡%' and birthday>='1970-01-01'`
连贯操作分开写也是没有问题的



