Monday, 16 August 2010

Running a DB Query

If you want to run a raw query from your magento module it is possible using the following codes: Open db connections
Read connection : $db = mage::getSingleton('core/resource')->getConnection('core_read'); Write connection : $db = mage::getSingleton('core/resource')->getConnection('core_write'); Execute your query given in $query
Run Query: $db->query($query); Finally fetch results:
Fetch Results (array): $db->fetch();

2 comments: