magento--------------数据库操作

本文介绍如何在Magento中高效查询特定产品,包括使用实体ID进行精确筛选、读取适配器的选择及Varien_Db_Select的灵活运用。

1
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getSelect()->where('e.entity_id in (?)', $ids);
$collection->addAttributeToSelect('*');
2
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');

$select = $read->select()
->from(array('cp'=>$categoryProductTable))
3
$categoryProductTable = $resource->getTableName('catalog/category_product');
4
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix().
5

通过读写适配器得到的是:
Varien_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql
然后通过select()方法得到的是:Varien_Db_Select extends Zend_Db_Select

$select = $this->_getReadAdapter()->select()
->from($this->getTable('store'))
->where('post_id = ?', $object->getId());


protected function _getReadAdapter()
{
return $this->_getConnection('read');
}


也就是说通过collection->getSelect()和
Mage::getSingleton('core/resource')->getConnection('catalog_read')->select()得到的都是Varien_Db_Select extends Zend_Db_Select

故。。。。。。。。。。。很好使用,看好Varien_Db_Select 和Zend_Db_Select的方法,就可以随意的使用已经封装好的函数!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值