zoukankan      html  css  js  c++  java
  • 容易产生错误的where条件

    错误的方式:
    $where = [];
    if ($type == 'wait') {
    $where['status'] = 0;
    }
    if ($type == 'done') {
    $where['status'] = ['exp', '=1 or status = 2'];
    }
    $where['employee_id'] = $id;

    return DB::M()
    ->table(self::TABLE)
    ->where($where)
    ->order('add_time desc')
    ->select();


    SQL:
    1:SELECT * FROM oa_employee_bill WHERE `status`='0' AND `employee_id`='4' ORDER BY add_time desc [Exec:0.00058984756469727s]
    2:SELECT * FROM oa_employee_bill  WHERE  `employee_id`='4'  ORDER BY add_time desc [Exec:0.00065398216247559s]
    3:SELECT * FROM oa_employee_bill  WHERE  `status`  =1 or status = 2 AND `employee_id`='4'  ORDER BY add_time desc [Exec:0.00068211555480957s]
    WHERE  (`status`  =1 )or (status = 2 AND `employee_id`='4') 

    正确的方式:
    $where = [];
    if ($type == 'wait') {
    $where['status'] = 0;
    }
    if ($type == 'done') {
    $where['status'] = ['exp', '>0 and status < 3'];
    }
    $where['employee_id'] = $id;

    return DB::M()
    ->table(self::TABLE)
    ->where($where)
    ->order('add_time desc')
    ->select();

    SQL:
    1: SELECT * FROM oa_employee_bill  WHERE  `employee_id`='4'  ORDER BY add_time desc [Exec:0.00057578086853027s]
    2: SELECT * FROM oa_employee_bill  WHERE  `status`='0' AND `employee_id`='4'  ORDER BY add_time desc [Exec:0.00056815147399902s]
    3: SELECT * FROM oa_employee_bill  WHERE  `status`  >0 and status < 3 AND `employee_id`='4'  ORDER BY add_time desc [Exec:0.00062203407287598s]
     WHERE  `status`  >0 and status < 3 AND `employee_id`='4' 只是一个情况


  • 相关阅读:
    串口基本知识
    20180826
    20180819
    自动化测试
    说话有重点 测试思维
    学习C语言,在软件测试中如何用?
    PC能替代服务器吗?
    服务器与普通电脑的区别?
    k8s 回滚应用
    k8s Service
  • 原文地址:https://www.cnblogs.com/Cxymds/p/5329136.html
Copyright © 2011-2022 走看看