Follow by Email

Wednesday, May 16, 2012

Execute custom SQL query in magento

This is the code to run custom sql in magento.

$resource = Mage::getSingleton('core/resource');
$conn = $resource->getConnection('core_read');
$results = $conn->query("SELECT pv.value,pv.entity_id FROM catalog_product_entity_varchar pv,catalog_product_entity pe where pv.attribute_id=65 and pv.value like '%".$query."%' and pv.entity_id=pe.entity_id and pe.type_id='configurable'")->fetchAll();   

2 comments:

  1. For executing sql query in magento, needed to a single connection code. Its so simple to execute raw sql query in magento. Just follow http://www.webinbangla.com/execute-sql-query-in-magento

    ReplyDelete