簡體   English   中英

Zend Framework 2 - Where 子句

[英]Zend Framework 2 - Where Clause

我想用這種方法添加一個 where 子句。

public function fetchAll()
{
    $resultSet = $this->select();
    return $resultSet;
}

我是這樣添加的。

public function fetchAll()
{
    $resultSet = $this->select();
    $resultSet->where("status = ?", 1);
    return $resultSet;
}

但是,它顯示了以下錯誤。

致命錯誤:調用未定義的方法 Zend\\Db\\ResultSet\\ResultSet::where()

你能幫我用上面提到的方法添加 WHERE、OR WHERE、GROUP 和 ORDER。

希望這會幫助你:

    public function Profile($accountid)
    {
        $result = $this->select(function (Select $select) use ($accountid) {
            $select
                ->columns(array(
                    'datefrom',
                    'available',
                    'used',
                    'details'
                ))
                ->where($this->adapter->getPlatform()->quoteIdentifier('accountid') . ' = ' . $this->adapter->getPlatform()->quoteValue($accountid));
        });

        $row = $result->current();

        if (!$row) {
            throw new \Exception('could_not_find_row');
        }

        return $row;
    }

您還可以執行$sql->select()->where(array('status' => 1))$table->select(array('status' => 1)) (煩人,希望他們使用相同的句法)。

您將一個關聯數組與映射column => value傳遞給 where(並且由於它是一個數組,您可以為其提供多個子句)。 Diemuzi 的方法適用於復雜的標識符,但對於簡單的比較,這是一種更具可讀性的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM