XWork where查询支持OR查询

2016-06-21  本文已影响0人  小默solo_frank

修改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;
上一篇下一篇

猜你喜欢

热点阅读