开发者

Zend DB returning NULL value

开发者 https://www.devze.com 2022-12-25 01:06 出处:网络
I have the following query that extends from Zend_DB_Table_Abstract $select = $this->select() ->from(\'expense_details\',

I have the following query that extends from Zend_DB_Table_Abstract

$select = $this->select()
            ->from('expense_details',
             array('SUM(expense_details_amount) AS total'))
        ->where('YEAR(expense_details_date) = ?', '2010')
            ->where('MONTH(expense_details_date) = ?', '01')
            ->where('expense_details_linkemail = ?', 'xxxx@gmail.com');

However it returning a NULL value despite its "equivalent" returning the desired value

SELECT SUM(expense_details_amount) AS total FROM expense_details
WHERE 
YEAR(expense_details_date) = '2010'   开发者_开发知识库                  
AND MONTH(expense_details_date) = '01'
AND expense_details_linkemail = 'xxxx@gmail.com'

Is my Zend_DB_Table construct above correct?


One thing that might be a problem is the 'AS' statement within this string literal.

array('SUM(expense_details_amount) AS total'))

Try changing it to this:

array('total' => 'SUM(expense_details_amount)'))

I believe this is how Zend_Db_Select handles AS.


After searching hard for a solution I found where the problem is.

I changed

$value = $this->fetchAll($select); 
$data[] = $value->total; 

to

$value = $this->fetchRow($select); 
$data[] = $value->total;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号