How to use a SQL function or perform calculations in a statement generating with Zend_Db_Select?

Answer

Actually, by default, if your expression includes parentheses, Zend_Db_Select will cast the statem
ent
appropriately
. However, if it does not, or you are having problems, you can use
Zend_Db_Expr to
explicitly create the expression:
1.
/****
Build the SQL:
2.
***
SELECT p."product_id", p.cost * 1.08 AS cost_plus_tax
3.
***
FROM "products" AS p
4.
**
*/
5.
$select = $db
-
>select()
6.
-
>from(array('p' => 'products'),
7.
array(
8.
'product_id',
9.
'cost_plus_tax' => new Zend_Db_Expr('p.cost * 1.08'),
10.
));

All zend Framework 2 Questions

Ask your interview questions on zend-framework-2

Write Your comment or Questions if you want the answers on zend-framework-2 from zend-framework-2 Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---