Magento run raw sql queries
1. Hello today we are going to share that how to run hardcode raw sql queries in magento.
2. For this you have to first create connection object to connect through database, there are two types of object, one for read and one for write.
3. Following code is to create connection object for read.
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
4. And Below code is for write.
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
5. After that you just nead to fire querie and handle data as follows.
$result=$read->query("SELECT * FROM table_mae WHERE column_name='value'");
$row = $result->fetch();
echo $row['column_name'];
/* or to insert values you can do something like this */
$write->query("Insert into table_name values('','','','')");
6. That is it you can save and run the code Enjoy!!
Categories:
magento
Tags:
magento raw queries
View Comments
Comment or Ask a Question
Quick Links