1
我有一個MySQL查詢,在PhpMyAdmin中完美工作,但在Zend Framework 1.12及其方法中使用時引發SQLSTATE[HY000]: General error
。那就是:SQLSTATE [HY000]:ZF1中MySQL變量的一般錯誤
SET @csum := 0;
SELECT s1.Date, (@csum := @csum + s1.total) as cumulative_sum
FROM (
SELECT c.datefield AS Date, IFNULL(SUM(subscription_total),0) AS total
FROM subscription s
RIGHT JOIN calendar c
ON c.datefield = DATE(subscription_date)
WHERE (c.datefield BETWEEN
(SELECT MIN(DATE(subscription_date)) FROM subscription)
AND
NOW()
)
GROUP BY DATE
) AS s1
如果我刪除了SET
聲明,但我需要設置一個MySQL變量,否則cumulative_sum
將只是NULL
值的語句不返回任何錯誤。下面是該方法的代碼:
public function findCumulativeCashflow($statut)
{
$db = $this->_getDbTable();
$dbAdapter = new Zend_Db_Adapter_Pdo_Mysql($db->getAdapter()->getConfig());
$sql = '<SQL statement above>';
$statement = $dbAdapter->query($sql);
$rows = $statement->fetchAll();
return $rows;
}
錯誤點$rows = $statement->fetchAll();
線,有另一種方法ZF與SET @var := value
使用?
任何想法將不勝感激。 謝謝!