一、使用Magento  resource 连接数据库,进行操作

  1. $db = Mage::getResourceSingleton('core/resource')->getConnection('core_write'); 
  2. $result = $db->query('SELECT `entity_id` FROM `catalog_product_entity`'); 
  3.   
  4. if(!$result) { 
  5.     return FALSE; 
  6.   
  7. $rows = $result->fetch(PDO::FETCH_ASSOC); 
  8.   
  9. if(!$rows) { 
  10.     return FALSE; 
  11.   
  12. print_r($rows); 

二、针对模块,采用zend 框架模式操作模块对应数据表格

  1. $resource = Mage::getSingleton('core/resource'); 
  2. $read = $resource->getConnection('core_read'); 
  3. $categoryProductTable=$read->getTableName('category/category_product') 
  4. $select = $read->select()->from(array('cp'=>$categoryProductTable))->where('cp.category_id=?', '3'); 
  5. $products=$read->fetchAll($select); 
  6. foreach($products as $row
  7. $product = Mage::getModel('catalog/product')->load($row['product_id']); 
  8. echo $product->getName();