How to write a custom SQL query in Magento?

If you want execute a SQL query in your Magento database in your program, you can write it by using the following code

// fetch write database connection that is used in Mage_Core module
$write = Mage::getSingleton('core/resource')->getConnection('core_write');

// now $write is an instance of Zend_Db_Adapter_Abstract
$write->query("insert into tablename values ('aaa','bbb','ccc')");

Aug 25, 2010 Posted in: Magento Developer Notes Bookmark and Share

One Response so far | Have Your Say!

  1. Ravi
    March 9th, 2011 at 12:36 pm

    gud

Leave a Feedback

Twitter Posts

Blog Search