在zend framework 2.2中选择查询,其中包含多个where子句和desc命令

时间:2014-03-14 06:52:51

标签: zend-framework zend-framework2

在zend framework 2.2中选择查询,其中包含多个where子句和desc。

我的查询是

Select 'vch_no' from vaucher_mst where 'series_sno'=12 and vchtype_sno=13 order by vch_no,desc

如何执行此查询?这是我的尝试:

public function getvchno() {
    $select = new select();
    $select->from($this->table);
    $this->select('vch_no');
    $where = new where();
    $where->equalTo('series_sno',12);
    $where->equalTo('vchtype_sno',13);
    $select->where($where);
    $order_by='vch_no';
    $order=Select::ORDER_DESCENDING;
    $select->order($order_by . ' ' . $order);
    $limit=1;
    $select->LIMIT(1);
    $statement = $this->select($select);
    print_r($statement);die;
    if (!$row) {
        throw new \Exception("Could not find row $id");
    }
}

1 个答案:

答案 0 :(得分:0)

我不知道Zend 2,但根据doc,这应该有效:

// Select 'vch_no' from vaucher_mst where 'series_sno'=12 and vchtype_sno=13 order by vch_no,desc
$select = new Select();
$select->from('vaucher_mst')
       ->columns(array('vch_no'))
       ->where(array('series_sno = 12', 'vchtype_sno = 13'))
       ->order('vch_no DESC');

让我知情:)