在magento中,要操作数据库,首先你需要一个resource model(翻译成"资源模型",magento中把数据库模型类称为一种资源(当然是相对程序来说的)),然后通过这个resource获取一个对数据库的连接.这样你就得到了一个Varien PDO Adapter对象,通过这个对象就可以直接通过sql语句操作.
view plaincopy to clipboardprint?
$w = Mage::getSingleton(’core/resource’)->getConnection(’core_write’);
$result = $w->query(’select ’entity_id’ from ’catalog_product_entity’);
if (!$result) {
return false;
}
$row = $result->fetch(PDO::FETCH_ASSOC);
if (!$row) {
return false;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xinhaozheng/archive/2009/03/30/4035124.aspx