Debugging SQL queries in Drupal 7 Or Print the $Query in Drupal

1). Install the Devel module

2). Now use the function Debugging SQL queries :

dpq($query)

Note : You can also use the following methods to print the $query object:

1). $query->__toString();
2). print (string)$query;