I want to convert following sql query to zend query. How I can convert this mysql query into zend query with zend framework 2?
SELECT SUM(amount)
FROM tbl_sale_amount
WHERE sale_type_id=7459650 AND YEAR(db_add_date) = YEAR(CURDATE());
NOTE: Need to fetch sum of amount for current year from tbl_sale_amount.
Thanks
GOT MY ANSWER HERE: ZF2 Query WHERE clause with DATE() for datetime column
Use this
$stmt = $db->query('SELECT SUM(amount)
FROM tbl_sale_amount
WHERE sale_type_id= ? AND YEAR(db_add_date) = YEAR(CURDATE()',
array($sale_type_id)
);
$result = $stmt->fetchAll();
$stmt->closeCursor();
if ($result) {
return $result;
} else {
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.