3

我想用这个方法添加一个 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。

4

2 回答 2

1

你也可以做$sql->select()->where(array('status' => 1))or $table->select(array('status' => 1))(烦人,希望他们使用相同的语法)。

您将关联数组与映射传递到 where column => value(因为它是一个数组,您可以给它多个子句)。Diemuzi 的方式适用于复杂的标识符,但这是一种更易读的简单比较方式。

于 2013-01-20T22:45:05.353 回答
1

希望这会帮助你:

    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;
    }
于 2013-01-17T14:53:17.247 回答