TP5的whereOr方法多條件存在

2021-10-05 15:37:55 字數 844 閱讀 8254

$where['a'] = '1';

$where['b'] = '2';

$where['c'] = '3';

$whereor['a'] = '1';

$whereor['b'] = '2';

$whereor['c'] = '3';

$data = db::name('matorder')->where($where)->whereor($whereor)->select();

這樣查出來的結果不是我想要的,sql語句為

select * from `table` where  `a` = '1'  and `b` = '2'  and `c` = '3'  or `a` = '1'  or `b` = '2'  or `c` = '3';

我想要的是這樣的乙個查詢語句:

select * from `table` where  (  `a` = '1'  and `b` = '2'  and `c` = '3' ) or (  `a` = 1  and `b` = '2'  and `c` = '3' );

後來看手冊,發現可以通過混合查詢達到效果,下面是手冊圖:

因為自己之前用的閉包不多,所以不怎麼了解閉包傳參,還好後面查到了

$data = db::name('table')->where(function ($query) use ($where) )->whereor(function ($query) use ($whereo) )->select();

這就是想要的結果了,此文僅為記錄防止忘記

tp5 提公升效能小方法

想要提公升系統效能,盡可能減少對資料庫的讀操作 1.首先,專案上線之前,要把config配置檔案中的除錯模式關閉 2.生成資料表字段快取optimize schema 每次有資料要查詢時,tp5會都會show columns去動態獲取表下面的資訊,增加了效能消耗 所以要生成資料表字段資訊快取,提公升...

TP5多條件搜尋,同時有必要條件

model this model 查詢是否有搜尋引數 search input get.search trim input get.search false list model if search 必要條件 list list where ispublic 1,isdel 0 order sort...

TP5常量參考

ext 類庫檔案字尾 php think version 框架版本號ds 當前系統的目錄分隔符 think path 框架系統目錄 root path 框架應用根目錄 lib path 系統類庫目錄 預設為 think path.library core path 系統核心類庫目錄 預設為 lib ...