使用占位符的优点:
1.占位符可以预先编译,提高执行效率
2.增加代码可读性
3.防止SQL注入
事例,使用占位符 、tp5 SQL判断两个时间段是否有交集:
//:salary就是命名占位符
$sql = "select id from web_teacher_trip where not ((end_time < :startDate) OR (start_time > :endDate)) and status IN (2, 4) and teacher_id = :teacher_id and id != :id";
$check_teacher = Db::query($sql,['startDate'=>$data['start_time'],'endDate'=>$data['end_time'],'id'=>$data['id'],'teacher_id'=>$data['teacher_id']]);