thinkphp5.1构建查询数组,$where可以是二位数组或三维数组,
Db::table(‘think_user‘)
->where([
[‘name‘, ‘like‘, $name . ‘%‘],
[‘title‘, ‘like‘, ‘%‘ . $title],
[‘id‘, ‘>‘, $id],
[‘status‘, ‘=‘, $status],
])
->select();
$map = [
[‘name‘, ‘like‘, ‘thinkphp%‘],
[‘title‘, ‘like‘, ‘%thinkphp‘],
[‘id‘, ‘>‘, 0],
];
Db::table(‘think_user‘)
->where([ $map ])
->where(‘status‘,1)
->select();
发现构建查询数组时,如果要指定数字下标,第一个下标必须是0,源码 thinkphp\library\think\db\Builder.php 305行
if (key($value) !== 0) {
throw new Exception(‘where express error:‘ . var_export($value, true));
}
thinkphp5.1 Array to string conversion问题 where express error:问题