Archive for : February, 2011

Magento – use singleton database connection

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
}
}