PUBLISHED: Feb 1, 2012 1 min read

Logging Database Queries in Magento

Tom DiDomenico

Tom DiDomenico

Senior Vice President, Digital Strategy & Technology

Sometimes Magento does something and it’s just not obvious why.  We’ve all heard “why aren’t my products showing up?” more times than we can count.  Magento’s object model for building queries is great, but sometimes you just need to see the sql that’s being run on the database in order to know what’s really going on.

In the past I’ve used the general log in mysql.  That can be a great source of information, but, depending on the version of mysql, it can be a pain to set up.  Other times I’ve inserted logging code into various db classes in order to print out queries that are being run, but I always have to find the right place again.  But today I stumbled on this blog entry – that spells out exactly how you can turn on some (as far as I know) undocumented logging functionality that is built right in to the Magento data access layer.  Kudos to the author and thanks for sharing!