[英]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.