I discovered a very strange problem in TP5. In TP3.2, you can use multi-dimensional arrays in a where to set multiple query conditions (sub-conditions)
For example:
where([array('id'=>'1','username'=>'2'),array('username'=>'3','password'=>'4'),'_logic'=>'or'])->find();
The sql generated by this code is
WHERE ( id
= '1' AND username
= '2' ) OR ( username
= '3' AND password
= '4' ) LIMIT 1
The parenthesis above is a sub-condition, which is very clear. However, in TP5, the '_logic' field is no longer supported. Instead, the where and whereOr methods are used. It seems that SQL can no longer be generated in the form of sub-conditions. So, How can I write a complex where statement? Please give me some advice.
大家讲道理2017-05-16 12:04:19
Arrays are supported:
$map['name'] = 'thinkphp';
$map['status'] = 1;
Db::table('think_user')->where($map)->select();
You can directly use string query
where("id = '1' AND username = '2'")->find();
It is recommended that you check the document directly:
Query method