常用的tp5多条件查询拼接
1,Where 条件表达式格式为:
$map['字段名'] = array('表达式', '操作条件');
2,以查询user表为例
$User = model("User"); // 实例化User对象
方法1:
$User->where('type=1 AND status=1')->select();
方法2:
$User->where(['type'=>1, 'status'=>['in',[1,2]],'regtime'=>['>=',strtotime('-1 day')]])->select();
方法3:
$User->where(['status'=>1])->whereor(['status'=>2])->select();
方法4:
$User->where(['name'=>'张三','status'=>1])->where(function ($query) {
$query->where(['age'=>20])->whereor(['sex'=>1]);
})->find();
方法5:
$User->where(['uid'=>['gt',1],'_string'=>' (name like "%张%") OR ( title like "%测试%") '])->select();
补充:
获取一周零两天四小时五分钟两秒后时间
date("Y-m-d H:i:s",strtotime("+1 week 2 days 4 hours 5 minute 2 seconds"));