Magento debug and print mysql query

Sometimes it happens while debugging we want to see the mysql query. So below is the code which when called on a collection will display the query for that collection.

var_dump($productCollection->printLogQuery(true));

I found a better version for the same below

var_dump($collection->getSelect()->__toString());

This will give you only the query.

This entry was posted in Magento. Bookmark the permalink.

2 Responses to Magento debug and print mysql query

  1. Thanks for sharing..

  2. Naleen Subedi says:

    Thanks, It worked for me.