maniwebertech maniwebertech - 6 months ago 18
MySQL Question

How can I query to database from zend framework view (phtml)?

I need to access database from phtml (view) in zend. how can i do that?

$stmt = $db->query('SELECT * FROM mcommerce_cart');

Answer

Well, you should not do this (it's bad practice). Recommend way is to access DB via models. You can pass data to view from Controller, Zend_View_Helper or (also no so recommeneded) via direct call to model. But if you really want to access DB in View than you can get Default Adapter by calling $db = Zend_Db_Table::getDefaultAdapter();