Last Updated: February 25, 2016
·
568
· hurel_clement

Drupal 7 Query Debug

In drupal 7 if you want to debug a query you can use devel module with :
dpq

Or use this function :

function _get_query_string(SelectQueryInterface $query) {
    $string = (string) $query;
    $arguments = $query->arguments();  
    if (!empty($arguments) && is_array($arguments)) {
      foreach ($arguments as $placeholder => &$value) {
        if (is_string($value)) {
          $value = "'$value'";
        }
      }

      $string = strtr($string, $arguments);
    }

    return $string;
 }