有时希望在Magento模块中写一些SQL语句,绕过资源模型,可以这样
1.
protected function _getResource()
{
return Mage::getSingleton('core/resource');
}
2.插入操作
$table = $this->_getResource()->getTableName('supplier_serviceprice');
$this->_getResource()->getConnection('core_write')
->insert($table, array('product_id' => $productId, "supplier_id" =>$receiverSuppliers[$i],"service_price" => $receiverPrice[$i],"is_primary"=>$primaryReceiver[$i]));
3.删除操作
$table = $this->_getResource()->getTableName('supplier_serviceprice');
$this->_getResource()->getConnection('core_write')->delete($table, $this->_getResource()->getConnection('core_write')->quoteInto('product_id=?', $this->_getProduct()->getId()));
另一种方法
$read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' ); $results = $read->fetchAll("SELECT supplier_paypal,service_price,is_primary FROM supplier_serviceprice ss INNER JOIN supplier s ON ss.supplier_id = s.supplier_id"); echo $results['字段名'] }