美文网首页
XWork where查询支持OR查询

XWork where查询支持OR查询

作者: 小默solo_frank | 来源:发表于2016-06-21 10:46 被阅读0次

    修改phplib/XWork/Db.php文件中buildConds()方法,原:

     private function buildConds($arrConds, &$conds, &$bind) {
            if (!$arrConds) {
                return;
            }
            if (is_array($arrConds)) {
                foreach ($arrConds as $name => $value) {
                    if (is_int($name)) {
                        $conds .= " AND $value ";
                    } else {
                        $conds .= " AND $name ?";
                        $bind[] = $value;
                    }
                }
            } else {
                $conds = $arrConds;
            }
        }
    

    修改后:

    private function buildConds($arrConds, &$conds, &$bind) {
            if (!$arrConds) {
                return;
            }
            if (is_array($arrConds)) {
                foreach ($arrConds as $name => $value) {
                    if (is_int($name)) {
                        $conds .= " AND $value ";
                    } else {
                        if(strpos($name,'OR ') !== false) {
                            $conds .= " $name ?";
                        } else {
                            $conds .= " AND $name ?";
                        }
                        $bind[] = $value;
                    }
                }
            } else {
                $conds = $arrConds;
            }
        }
    

    使用:

    $cond['OR admin_id='] = 1;

    相关文章

      网友评论

          本文标题:XWork where查询支持OR查询

          本文链接:https://www.haomeiwen.com/subject/jvhgdttx.html