php - TP5 where method problem
大家讲道理
大家讲道理 2017-05-16 12:02:19
0
1
624

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.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
大家讲道理

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template