Magento 1 – How to Log SQL Query of the Collection

collection;logmagento-1sql

I want to log the SQL query for a custom collection. I tried the following code. But did not work. Any suggestions will be appreciated.

Mage::log($collection->getSelect(),null,'test.log',true);

Best Answer

If you want the SQL query from a collection you need to cast it as string. Just add (string) to your previously written logging code.

Mage::log((string)$collection->getSelect(),null,'test.log',true);
Related Topic