-
-
Save rodde177/295cba3af4c654b3c4a8d1ab23a198f5 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