Home > PHP Framework > YII > How to query multiple or in andWhere in YII2

How to query multiple or in andWhere in YII2

angryTom
Release: 2019-11-26 17:12:57
forward
4289 people have browsed it

How to query multiple or in andWhere in YII2

How to query multiple ors in andWhere in YII2

Complex query using multiple ors:

AND ((`name`='张三') OR (`name`='李四') OR (`name`='王五'))
Copy after login
// AND ((`name`='张三') OR (`name`='李四') OR (`name`='王五'))
$query->andWhere(['or',
    ['name' => '张三'],
    ['name' => '李四'],
    ['name' => '王五']
]);
Copy after login
AND (((name=‘张三’) AND (phone=‘15200000000’)) OR ((name=‘李四’) AND (phone=‘15300000000’)))
Copy after login
// AND (((`name`='张三') AND (`phone`='15200000000')) OR ((`name`='李四') AND (`phone`='15300000000')))
$query->andWhere(['or',
    ['and',
        ['name' => '张三'],
        ['phone' => '15200000000']
    ],
    ['and',
        ['name' => '李四'],
        ['phone' => '15300000000']
    ]
]);
Copy after login

Recommended: " YII Tutorial

The above is the detailed content of How to query multiple or in andWhere in YII2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template