Forked from deivisonarthur/direct-sql-queries-in-magento.php
Created
May 26, 2016 02:49
-
-
Save VIVEKLUCKY249/07be7f1a4e16e430053d4819c2ce807b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| //Table names and table prefixes | |
| $tableName = Mage::getSingleton('core/resource') | |
| getTableName('catalog_product_entity'); | |
| // if prefix was 'mage_' then the below statement | |
| // would print out mage_catalog_product_entity | |
| echo $tableName; | |
| //Accessing the database connection resource | |
| $read = Mage::getSingleton('core/resource')->getConnection('core_read'); | |
| $write = Mage::getSingleton('core/resource')->getConnection('core_write'); | |
| //For a list of functions available, copy the following code into a Magento template. | |
| $read = Mage::getSingleton('core/resource')->getConnection('core_read'); | |
| echo '<pre>'; | |
| print_r(get_class_methods($read)); | |
| echo '</pre>'; | |
| exit; | |
| //Reading data from the database | |
| $read = Mage::getSingleton('core/resource')->getConnection('core_read'); | |
| $query = 'SELECT * FROM '. Mage::getSingleton('core/resource')->getTableName('catalog_product_entity'); | |
| $results = $read->fetchAll($query); | |
| print_r($results); | |
| //Writing information to the database | |
| $write = Mage::getSingleton('core/resource')->getConnection('core_write'); | |
| // Add your own query below | |
| // I didn't add one as I didn't want you to run the code | |
| // and me break your database! | |
| $query = 'add your query here'; | |
| $write->query($query); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment