Created
August 28, 2015 11:30
-
-
Save srinathweb/c2fb6dcb9ef13b731540 to your computer and use it in GitHub Desktop.
magento quering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://fishpig.co.uk/magento/tutorials/direct-sql-queries/ | |
Yes you can run direct sql queries within Magento, the best way to do this is to use the read write resource. You can insatiate it with: | |
$resource = Mage::getSingleton('core/resource'); | |
$readConnection = $resource->getConnection('core_read'); | |
$writeConnection = $resource->getConnection('core_write'); | |
To run a select you can do something like this: | |
$readConnection = $resource->getConnection('core_read'); | |
$query = 'SELECT * FROM ' . $resource->getTableName('catalog/product'); | |
$results = $readConnection->fetchAll($query); | |
/* get the results */ | |
var_dump($results); | |
To write something to the database use: | |
$resource = Mage::getSingleton('core/resource'); | |
$writeConnection = $resource->getConnection('core_write'); | |
$table = $resource->getTableName('catalog/product'); | |
$query = "UPDATE {$table} SET {item} = '{value}' WHERE entity_id = 'value'"; | |
$writeConnection->query($query); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment