在我们一般使用这个框架中,where条件是依数组的形式来呈现的。比如说:
->where(['field'=>select])
但是,如果是数组的形式,无法满足我们的whereOR,因为数组在where条件中会转换成whereAnd。
这个时候,我们就可以使用where中的字符串形式。
->where('a=1 AND b=2 or c=3')
这样是不是很方便呢?看下图。
Db::table('think_user')->where('type=1 AND status=1')->select();
转成的sql是:
SELECT * FROM think_user WHERE type=1 AND status=1
为了安全,我们可以写成:
Db::table('think_user')->where("id=:id and username=:name")->bind(['id'=>[1,\PDO::PARAM_INT],'name'=>'thinkphp'])->select();