所以我正在尝试完成这样的事情:
SELECT * FROM table WHERE status_id IN (1,3,4);
使用Zend_Db_Select ...找不到方法:(完全有可能吗?
Answers:
您也可以像这样使用它:
$data = array(1,3,4);
$select->where('status_id IN(?)', $data);
您不需要内爆数组,它更安全
第一个答案可能在ZF1中有效,但在Zend Framework 2中无效:
$data = array(1,3,4);
$select->where('status_id IN(?)', $data);
万一Zend Framework2我发现您必须使用:
$data = array(1,3,4);
$select->where(array('status_id' => $data));
结果:
WHERE `status_id` IN ('1', '3', '4')
我在任何地方都找不到此文件!ZF文档通常不是最佳的。
我们可以使用Zend\Db\Sql\Predicate\In
与Zend\Db\Sql\Where
制作在查询模型中。
$this->status_ids = array(1,3,4);
// select attributes from db by where in
$result = $this->select(function (Select $select) {
$predicate = new In();
$select->where(
$predicate->setValueSet($this->status_ids)
->setIdentifier('status_id')
);
})->toArray();
This solution works well with zf2
$ids = array('1', '2', '3', '4', '5', '6', '7', '8');
$select->where(array("app_post_id"=> $ids));
要么
$ids = array('1', '2', '3', '4', '5', '6', '7', '8');
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->from('app_post_comments');
$select->where(array("app_post_id"=> $ids));
// echo $select->getSqlString($this->adapter->getPlatform());
// exit;
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$resultSet = new ResultSet();
$resultSet->initialize($result);
$resultSet->buffer()->toArray();
echo '<pre>';
print_r($resultSet);
exit;
return $resultSet;
$completionNo = implode(",",$data);
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$select = $db->select()->from(array("p"=>PREFIX . "property_master"),array('id','completion_no','total_carpet_area'))->where("p.completion_no IN (?)", $completionNo);