Zend DB returning NULL value
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;
精彩评论