• 容易产生错误的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' 只是一个情况


  • 相关阅读:
    圈水池 nyoj 78 凸包算法
    凸包算法入门
    nyoj 633 幂
    软件下载地址
    概率论与数理统计
    迷宫最短路径 问题
    将项目发布至开发环境测试环境的方法
    一些JavaScript技巧
    随机生成10个不重复的0-100的数字
    Git添加远程库和从远程库中获取(新手傻瓜式教学)
  • 原文地址:https://www.cnblogs.com/Cxymds/p/5329136.html
Copyright © 2020-2023  润新知