我有一个 MySQL 查询,它在 PhpMyAdmin 中运行良好,但SQLSTATE[HY000]: General error
在 Zend Framework 1.12 及其fetchAll()
方法中使用时会抛出一个错误。这里是:
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
吗?
任何想法将不胜感激。谢谢!