PHP / Magento – Direct SQL Queries

Not the cleanest but here’s a quick solution to do a direct query on Magento. Might be faster than calling Magento’s objects ?

 /**
   * Get the resource model
   */
$resource = Mage::getSingleton('core/resource');
     
 /**
  * Acccess to the database in read only
  */
$readConnection = $resource->getConnection('core_read');
     
$query = 'SELECT * FROM ' . $resource->getTableName('catalog/product');
     
/**
 * Execute the query  
 */
$results = $readConnection->fetchAll($query);

Thank you DevProblems !


SQL Magento – Get store credit balance

Valid for Magento EE only. The feature of store credits isn’t native in CE edition.

select amount 
from enterprise_customerbalance 
where customer_id = @customer_id ;