在Magento中,要操作数据库,首先你需要一个resource model(翻译成”资源模型”,magento中把数据库模型类称为一种资源(当然是相对程序来说的)),然后通过这个resource获取一个对数据库的连接。这样你就得到了一个Varien PDO Adapter对象,通过这个对象就可以直接通过sql语句操作。

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

比如我想通过订单ID,来查询‘支付方式’和‘订单总价’
这个功能MAGENTO已经有这样的接口了

$order = Mage::getModel(‘sales/order’)->load(‘order_id’); //取出订单号为order_id的订单
$order->getPayment();