Magento – How to print collection thesql query in magento


Let's say I have a collection like:

$products = Mage::getModel('catalog/product')

How do I print the actual MySQL code that gets executed?

Best Solution

You can always view your sql query at a certain point by echoing getSelect as shown:

$products = Mage::getModel('catalog/product')
echo $products->getSelect();

To change query parameters you want to check out methods like:

$products->addAttributeToFilter('someattribute', array('eq'=>'1'));