在我們一般使用這個框架中,where條件是依陣列的形式來呈現的。比如說:
->where(['field'=>select])
但是,如果是陣列的形式,無法滿足我們的whereor,因為陣列在where條件中會轉換成whereand。
這個時候,我們就可以使用where中的字串形式。
->where('a=1 and b=2 or c=3')
這樣是不是很方便呢?看下圖。
db::table('think_user')->where('type=1 and status=1')->select();
轉成的sql是:
select * from think_user where type=1 and status=1
為了安全,我們可以寫成:
db::table('think_user')->where("id=:id and username=:name")->bind(['id'=>[1,\pdo::param_int],'name'=>'thinkphp'])->select();
tp5框架原理詳解 TP5框架安全機制例項分析
防止sql注入 1 查詢條件盡量使用陣列方式,具體如下 wheres array wheres account account wheres password password user where wheres find 2 如果必須使用字串,建議使用預處理機制,具體如下 user d useri...
tp5帶條件分頁
前台寫個hidden的input,後台 分頁引數 num input get.pagelist post和get需要和前台提交的時候保持一致否則無效 case lists db table think case where map field field order id asc paginate ...
TP5的whereOr方法多條件存在
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語句為 selec...