Home> PHP Framework> ThinkPHP> body text

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

藏色散人
Release: 2021-04-13 08:57:56
forward
4805 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
source:csdn.net
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!