在Zend Framework中使用MySQL查询选择字符串/数字

时间:2011-12-27 13:27:45

标签: zend-framework

我正在尝试在Zend Framework 1.11中实现以下MySQL查询:

SELECT [other_columns], 1 AS dontShow FROM deal_merchants;

我有兴趣选择数字1并给它dontShow别名。但是当我运行以下代码时:

$select = $this->select(Zend_Db_Table::SELECT_WITHOUT_FROM_PART);
$select->setIntegrityCheck(false)
       ->from('deal_merchants',array('MIN(BidPrice) AS price','USERS_ID','MIN(BidQuotaFrom) AS MinFrom','MAX(BidQuotaTo) AS MaxTo','users.ImageURL','1 AS dontShow'));

我得到以下异常:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'deal_merchants.1' in 'field list'

2 个答案:

答案 0 :(得分:0)

想出怎么做。不确定它是否是最好的方式,但它确实有效。如果有人绊倒了这个,那就是这样的:

$select = $this->select(Zend_Db_Table::SELECT_WITHOUT_FROM_PART);
$select->setIntegrityCheck(false)
       ->from('deal_merchants',array('MIN(BidPrice) AS price','USERS_ID','MIN(BidQuotaFrom) AS MinFrom','MAX(BidQuotaTo) AS MaxTo','users.ImageURL','(SELECT 1 FROM dual) AS dontShow'));

答案 1 :(得分:0)

您可以将列/别名作为键/值放入数组中,例如:

array('price' => 'MIN(BidPrice)', ...)

Key是别名,value是查询值。