How to Run Raw SQL Query on Zend Framework

This tutorial describes how to run raw SQL script inside a controller on Zend Framework.

For running non-queries, use the following:


Zend_Db_Table_Abstract::getDefaultAdapter()->query($sql);

In order to return a single row, use the following:


Zend_Db_Table_Abstract::getDefaultAdapter()->query($sql)->fetch(); 

To return all rows, use the following:


Zend_Db_Table_Abstract::getDefaultAdapter()->query($sql)->fetchAll();