Magento – Write Sql query

Simple step to execute MySQL query in Magento.
(1) Select SQL :

$objCon = Mage::getSingleton('core/resource')->getConnection('core_write');
$result = $objCon->query('SELECT 'entity_id' FROM 'catalog_product_entity');

if(!$result) {
$rows = $result->fetch(PDO::FETCH_ASSOC);
if(!$rows) {
print_r($rows);
}
}


(2) Insert SQL :

$objCon = Mage::getSingleton('core/resource')->getConnection('core_write');
$objCon->query("insert into table name (fields) values (values) ");

1 comment:

Terry Littrell said...

Thanks for giving information about magento.

magento development