Skip to content

Instantly share code, notes, and snippets.

@nahidacm
Last active May 26, 2016 02:49
Show Gist options
  • Save nahidacm/5253766 to your computer and use it in GitHub Desktop.
Save nahidacm/5253766 to your computer and use it in GitHub Desktop.
<?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