Home > PHP Framework > ThinkPHP > How to use where and whereor at the same time in tp5

How to use where and whereor at the same time in tp5

藏色散人
Release: 2021-04-13 08:57:56
forward
4951 people have browsed it

The following tutorial column will introduce to you how to use where and whereor in tp5 at the same time. I hope it will be helpful to friends in need!

Where and whereor in tp5 are used simultaneouslyHow to use where and whereor at the same time in tp5

One:

$data = db('table')->where(function($query) {
    $query->where('key1', value)->whereor('key1',value1);
})->where(['key2'=>value2,'key3'=>value3])->field('key4')->find();
Copy after login
The generated sql statement is:

find key4 FROM `table` WHERE  (  `key1` = 'value' OR `key1` = 'value1' ) and  `key2` = 'value2' 
 and 'key3' = 'value3';
Copy after login

Two:

$data = db('table')->where(function($query) {
    $query->where('key1', value)->whereor('key1',value1);
})->whereor(function($query){
    $query->where(['key2'=>value2]->whereor(['key3'=>value3]))
})->field('key4')->find();
find 'key4' FROM `table` WHERE  (  `key1` = value OR `key1` = value1 ) 
OR (  `key2` = 'value2' OR `key3` = 'value3' )
Copy after login

Related recommendations:

The latest 10 thinkphp video tutorials

The above is the detailed content of How to use where and whereor at the same time in tp5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
tp5
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
Latest Issues
Error running tp5 on tomcat
From 1970-01-01 08:00:00
0
0
0
tp5 video upload
From 1970-01-01 08:00:00
0
0
0
TP5 paging always has problems
From 1970-01-01 08:00:00
0
0
0
Set up that tp5.com
From 1970-01-01 08:00:00
0
0
0
tp5 search paging
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template