How to use magento core query for read and write?
magento

How to use magento core query for read and write?

KrikaSoft
14 Jul 2014 16:34

Most of the Magento developer preferred to use module model object or model resource object for Magento query, but even though some time need to use core query. To use core query method use below code.

/** Core resource object */
     $resource = Mage::getSingleton('core/resource');
/** Read adapter connection */
    $read= $resource->getConnection('core_read');
/** table name to fetch records */
     $clientsTable = $resource->getTableName('clients');
/** Select query with where clause and order by */
     $select = $read->select()
     ->from($clientsTable,array('clients_id','title','content','status'))
     ->where('status',1)
     ->order('created_time DESC') ;
/** Fetch records */
     $clients = $read->fetchRow($select);

/** Write adapter connection */
     $write = Mage::getSingleton('core/resource')->getConnection('core_write');
     $sql = "insert into tablename values (?, ?, ?)";
     $write->query($sql, array('aaa','bbb','ccc'));

Author

KrikaSoft
Hello, I'm
KrikaSoft

KrikaSoft offers innovative IT solutions and services to businesses worldwide. Specializing in Web development, Web customization, and Website design, we excel in Magento, WordPress, and other PHP frameworks. From Hybrid Application Development to seamless user experiences, trust us as your technology partner for reliable and cutting-edge solutions. Experience excellence with KrikaSoft!

Latest Post