How To Log All Magento SQL
How To Log All Magento SQL
If you want to be sure all SQL is actually logged, I suggest to use a third party software:
Neon Profile SQL is actually free and works fine
( you need to edit local.xml to attach Magento to Neon ... it works as a kind of SQL proxy logging
everything that pass through it)
In alternative a native Magento/Varien approach could be the following one:
1. edit lib/Varien/Db/Adapter/Pdo/Mysql.php
2. change the following properties to true (line 103 )
3. you will have a log file to be created here var/debug/pdo_mysql.log
Here line to be changed: ( comments are self explanatory )
protected $_debug = true;
protected $_logQueryTime = 0.05;
protected $_logAllQueries = true;
protected $_logCallStack = true;
In case you have enabled $_logCallStack you will have also a TRACE parte
2. Besides these basic information, one can get more info by calling “Varien_Profiler::getSqlProfiler($conn);”
like on the example shown below.
$conn = Mage::getSingleton('core/resource')->getConnection('core_setup');
$conn->getProfiler()->setEnabled(true);
echo Varien_Profiler::getSqlProfiler($conn);
3. Activate the Zend SQL Profiler with the following node in your app/etc/local.xml
<resources>
<default_setup>
<connection>
<profiler>1</profiler>
Then you can access the profiler somewhere in your code and retrieve a lot of informations about all executed
queries:
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')-
>getProfiler();
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')-
>getProfiler();
Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'queries.log', true);