Search This Blog

Wednesday, June 1, 2011

Magento - How to run a SQL query against the database

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

if(!$result) {
return FALSE;
}

$rows = $result->fetch(PDO::FETCH_ASSOC);

if(!$rows) {
return FALSE;
}

print_r($rows);