Print magento Sql at run time

August 5, 2010 | In: Magento, mysql

Any developer wants to check what sql is executing during page load. so he can check and identify the getting errors:

To print the sql go to folder :

app\code\core\Mage\Catalog\Model\

and open file Layer.php

search the function :

<?php
     public function getProductCollection()
?>

and replace :

<?php
     return $collection;
?>

to

<?php
    $collection->printlogquery(true);
    return $collection;
?>

and save and run front page again… you will see all Sqls are showing on the page.