天天看点

magento -- 在Magento中获取SQL语句

       magento是在zend framework的基础上搭建而来,有两种方式可以从magento的collection获得真正的sql语句。

以 mage::getresourcemodel('reports/product_collection') 为例:

1

         $collection=mage::getresourcemodel('reports/product_collection');

$collection->printlogquery(true); 

2

$query=$collection->getselectsql(true);

echo $query; 

         可以看到同样的输出结果

         select `e`.* from `catalog_product_entity` as `e`