Thursday 23 June 2011

Running Custom SQL Query in Magento.

As i explained previously that magento works on EAV model so, when ever custom sql query has been executed, It must be checked that the result must be combination of one to more tables.
<?php
// fetch read database connection that is used in Mage_Core module
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$read->query("SE...");
$row = $value->fetch();

print_r($row); // As Array

// For Write

// 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 ('magento','cool','work')");

?>

No comments:

Post a Comment