Thinkphp中各种常用的查询方式,日期查询,高级查询..

A AND (B OR C)

-> where('tStatus', '1')
-> where('tProjects = '.$info['tProjects'].' OR tTid = '.$info['tTid'])

A And B And C In (1,2)

$linshiA['id'] = $data['id'];
$linshiA['tMid'] = $data['tMid'];
$linshiA['tStatus'] = ['1','2'];
$getTaskFabuA = PublicService::getTaskFabuA($linshiA);

动态条件查询 when

Minfo::when($data['tStatus'],function($query) use ($data){
	$query->where('tStatus',$data['tStatus']);
    },$data['tTime'],function($query) use ($data){
	$query->whereBetweenTime('tTime',date('Y-m-d',time()));
})
-> count();

日期相关 - 通过CONVERT函数

Db::table('tUser_Tk') -> field('id,CONVERT(varchar,tLoginTime,120) as Time') -> select();

日期相关 - 快速查询今日,本周,本月,本年数据:

-> whereTime('create_time', 'd')
-> whereTime('create_time', 'w')
-> whereTime('create_time', 'm')
-> whereTime('create_time', 'y')
-> whereBetweenTime('tTime',date('Y-m-d',time()));

日期相关 - 日期对比是否过期

-> whereTime('tEndtime','>=',date('Y-m-d',time()))

日期相关 - 日期加一天 或者 指定日期加一天 day month year

$info['endTime'] = date('Y-m-d',strtotime('+1 day'));
$info['endTime'] = date('Y-m-d',strtotime('+1 day',strtotime($time)));

你可能感兴趣的:(Thinkphp)