To check all queries by a specific piece of code I am using:
Modify from protected to public the variable $_debug in Varien_Db_Adapter_Pdo_Mysql
Do the same for $_logAllQueries
Add this before code executes:
$adapter = Mage::getSingleton('core/resource')->getConnection('core_write');
$adapter->_debug = true;
$adapter->_logAllQueries = true;
Add this after the code
$adapter->_debug = false;
$adapter->_logAllQueries = false;
so your final code will look like this:
$adapter = Mage::getSingleton('core/resource')->getConnection('core_write');
$adapter->_debug = true;
$adapter->_logAllQueries = true;
Mage::getModel('catalog/product')->load(1);
$adapter->_debug = false;
$adapter->_logAllQueries = false;
Is there any other more elegant solution?
You can use a variation of my answer at How do I print all the queries in Magento?
Instead of activating the profiler globally in local.xml
, add these before and after the code you want to test:
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')->getProfiler();
$profiler->setEnabled(true);
// ...
Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'queries.log', true);
$profiler->setEnabled(false);
Then you will find the queries in var/log/queries.log
There is an extension available for Magento which i am personally using from long time (works for Community as well as EE) :
https://github.com/madalinoprea/magneto-debug
This will let you - Check all requests - See all SQL queries executed for a request - See all layout handles executed - and many more
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With