When debugging CiviCRM pages, is there a native way to emit the SQL statements being run, eg on a Search page? I'm looking for something easier than finding the code for the page and putting in a debug_var kind of statement. I'd prefer to not have to rely on a Drupal module like cTools, since we work with other CMSes frequently these days.

4 Answers 4


If you want to see everything, you can enable MySQL logging as follows (don't do this on production!):

  1. From the mysql console (or within an application like MySQL Workbench), run:

    SET global general_log = 1;
    SET global log_output = 'table';
  2. Look at all queries run within the last 15 seconds

    select * 
    from mysql.general_log 
      command_type = 'Query' and 
      event_time > now() - interval 15 second;
  3. Try to find queries on the civicrm_contact table

    select * from mysql.general_log 
      argument like '%civicrm_contact%' and 
      argument not like '%general_log%' 
    order by event_time desc;
  4. Clear the log

    truncate table mysql.general_log; 
  5. Turn off logging

    SET global general_log = 0; 

Try setting:

define('CIVICRM_DAO_DEBUG', 1);

in your civicrm.settings.php file, this might work based on a quick glance at the code.

The output will appear onscreen and in the CiviCRM log file (eg sites/default/files/civicrm/ConfigAndLog/CiviCRM*log or media/civicrm/ConfigAndLog/CiviCRM*log or wp-content/plugins/files/civicrm/ConfigAndLog/CiviCRM*log)


If your page happens to be a report, you can install the Extended Reports extension which will display the full sql query being run.


I am not sure wether such a functionality exist in CiviCRM but something wich might be worth a look at is the logfiles

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.