TP3.2之WHERE組合條件處理


1、條件都是int類型:

$User->where('type=1 AND status=1')->select();

2、條件包含字符串類型:

使用3.1以上版本的話,使用字符串條件的時候,建議配合預處理機制,確保更加安全,

$Model->where("id=%d and username='%s' and xx='%f'",$id,$username,$xx)->select();

或者:

$Model->where("id=%d and username='%s' and xx='%f'",array($id,$username,$xx))->select();

3、數組條件:

$User = M("User"); // 實例化User對象
$map['name'] = 'thinkphp';
$map['status'] = 1;
// 把查詢條件傳入查詢方法
$User->where($map)->select(); 

4、表達式查詢:比如大於,小於,不等於等

$map['a'] = array('gt',1);
$where['b'] = 1;
$Model->where($map)->where($where)->where('status=1')->select();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM