1

我需要使用各种参数的连接创建查询,例如:

SELECT foo.*, bar.* FROM foo LEFT JOIN bar ON foo.c1 = bar.c1 AND foo.c2 = bar.c2 WHERE foo c3 = "somedata";

问题是我找不到如何使用 FuelPHP Query Builder 创建“AND”。

谢谢。

4

3 回答 3

2

可以在一个连接中使用多个 ->on。在这种情况下,Builder 将使用“AND”组合它们。

于 2012-10-29T14:37:32.760 回答
0

他们编译 on 条件的方式使得无法设置像status= 1这样的值

我将函数 on_string 添加到 \Fuel\Core\Database_Query_Builder_Join

public function on_string($string) { 
    $this->_on_string = $string;
    return $this;
}

在编译()

       if ($this->_on_string == "") { //yau add on string
        $conditions = array();
        foreach ($this->_on as $condition) {
            // Split the condition
            list($c1, $op, $c2) = $condition;

            if ($op) {
                // Make the operator uppercase and spaced
                $op = ' ' . strtoupper($op);
            }

            // Quote each of the identifiers used for the condition
            $conditions[] = $db->quote_identifier($c1) . $op . ' ' . $db->quote_identifier($c2);
        }

        // Concat the conditions "... AND ..."
        $sql .= '(' . implode(' AND ', $conditions) . ')';
    } else {            
        $sql .= '(' . $this->_on_string . ')'; //yau add on string
    }

也要将您的方法公开给 Database_Query_Builder_Select。

    public function on_string($string)
{
    $this->_last_join->on_string($string);

    return $this;
}
于 2013-03-15T12:18:55.077 回答
0

我认为这不是陈顺佑所必需的。您可以根据字符串进行选择,但您需要像这样转义值:

->on('t.object_property', '=', \DB::quote($property));

于 2013-11-22T16:54:59.100 回答