//打印sql,where值为数组
$sql = Db::name('user')->where(['id'=>1])->buildSql();
dump($sql);
//结果:SELECT * FROM `user` WHERE `id` = 1
//打印sql,where值为两个参数
$sql2 = Db::name('user')->where('id',1)->buildSql();
dump($sql2);
//结果:SELECT * FROM `user` WHERE `id` = 1
//打印sql,where值为三个参数
$sql3 = Db::name('user')->where('id','=',1)->buildSql();
dump($sql3);
//结果:SELECT * FROM `user` WHERE `id` = 1
//打印sql,where多条件
$sql4 = Db::name('user')->where([
'id' => ['in',[1,2,3,4,5]],
'age' => ['gt',10]
])->buildSql();
dump($sql4);
//结果:SELECT * FROM `user` WHERE `id` IN (1,2,3,4,5) AND `age` > 10
//使用EXP表达式
$sql5 = Db::name('user')->where('id','EXP','not in (2,5)')->buildSql();
dump($sql5);
//结果:SELECT * FROM `bw_user` WHERE ( `id` not in (2,5) )
//可以使用连续的where条件
$sql6 = Db::name('user')
->where('id','EXP','not in (2,5)')
->where('age','>',10)
->buildSql();
dump($sql6);
//结果:SELECT * FROM `bw_user` WHERE ( `id` not in (2,5) ) AND `age` > 10
//如果多个where条件是or关系,使用whereOr
$sql7 = Db::name('user')
->where('id','EXP','not in (2,5)')
->whereOr('age','>',10)
->buildSql();
dump($sql7);
//结果:SELECT * FROM `bw_user` WHERE ( `id` not in (2,5) ) OR `age` > 10