Magento Team provides best solution for Magento eCommerce websites design and development.

22 October, 2012

Running Custom SQL Query in Magento

If you want to execute your own MySQL query in Magento, here is the solution.
$sql_core = Mage::getSingleton('core/resource')->getConnection('core_read');
$select = $sql_core->select()
->from('tablename', array('*'))  // select * from tablename
->where('id=?',1);               // where id =1
$rowsArray = $sql_core->fetchAll($select);   // return all rows