Magento: Direct MySQL query for create, read, update and delete
Magento database MySQL read and write adapters.
//database read adapter $read = Mage::getSingleton('core/resource')->getConnection('core_read'); //database write adapter $write = Mage::getSingleton('core/resource')->getConnection('core_write'); //Functions of read and write adapter $readMethods = get_class_methods(get_class($read));foreach($readMethods as $r){echo $r."\n";} $writeMethods = get_class_methods(get_class($write));foreach($writeMethods as $r){echo $r."\n";}
Magento Read Query, returns an array.
$results = $read->fetchAll("select * from customer_entity where email like '%@codexpedia.com'"); var_dump($results[0]); foreach($results as $r) { var_dump($r); }
Magento Insert Query.
$write->insert( "A_TABLE_NANE", array("a_column_name" => value, "a_column_name" => value) );
Magento Update Query.
$write->update( "A_TABLE_NANE", array("a_column_name" => value, "a_column_name" => value), "entity_id=18" );
Magento Delete Query.
$write->delete( "A_TABLE_NANE", "entity_id=18" );
Magento Raw Query. It can be used for create, read, update, and delete operations.
//raw query Varien_Db_Statement_Pdo_Mysql $customers = $read->query("select * from customer_entity"); var_dump($customers); foreach($customers as $c) { var_dump($c); }
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts