Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

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!!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home