Magento – use singleton database connection
Posted on: February 21, 2011 /
Categories: Magento
Magento database connection write mode:
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
Magento database connection read mode:
$db = Mage::getSingleton('core/resource')->getConnection('core_read');
Query model
$result = $db->query("SELECT * FROM tablename");
if ($result)
{
while ($row = $result->fetch(PDO::FETCH_ASSOC))
{
// Use $row
}
}