[英]Zend Framework 2 - Where Clause
I would like to add a where clause with this method.我想用这种方法添加一个 where 子句。
public function fetchAll()
{
$resultSet = $this->select();
return $resultSet;
}
I have added like this.我是这样添加的。
public function fetchAll()
{
$resultSet = $this->select();
$resultSet->where("status = ?", 1);
return $resultSet;
}
But, it shown the below error.但是,它显示了以下错误。
Fatal error: Call to undefined method Zend\\Db\\ResultSet\\ResultSet::where()致命错误:调用未定义的方法 Zend\\Db\\ResultSet\\ResultSet::where()
Could you please help me to add WHERE, OR WHERE, GROUP and ORDER with above mentioned method.你能帮我用上面提到的方法添加 WHERE、OR WHERE、GROUP 和 ORDER。
Hopefully this will help you out:希望这会帮助你:
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;
}
You can also do $sql->select()->where(array('status' => 1))
or $table->select(array('status' => 1))
(annoying, wish they used the same syntax).您还可以执行$sql->select()->where(array('status' => 1))
或$table->select(array('status' => 1))
(烦人,希望他们使用相同的句法)。
You pass where an associative array with the mapping column => value
(and since it's an array you can give it multiple clauses).您将一个关联数组与映射column => value
传递给 where(并且由于它是一个数组,您可以为其提供多个子句)。 Diemuzi's way is good for complex identifiers but this is a more readable way for simple comparison. Diemuzi 的方法适用于复杂的标识符,但对于简单的比较,这是一种更具可读性的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.