views:

36

answers:

2

Is it possible to return the actual SQL query as a string from the result of db_query?

Or otherwise take the returned resource ID from db_query and get the SQL string?

+1  A: 

I don't think it is. However if you are only doing so for the purpose of debugging you can turn on the devel module and that will show you the queries run.

Actually you could just set the variable 'dev_query' to 1 and then access the global array $queries, but I wouldn't recommend it.

Jeremy French
forgot about that feature, thanks!
AK
+1  A: 

I would recommend the use of the devel module. There is a setting devel offers which will show all queries run during the generation of a page at the bottom of the page, with data on query execution time and the function that called db_query(). If you have a general idea of what your query will look like or the function that called it, you could search for it within your browser and you can see what was actually send to the database.

timgeek

related questions