In your database abstraction class, the best way to do it is to add a debug option that logs queries and debug information to a file, or if there is enough overhead in your application, keep it all available in a variable you can inspect at runtime. Once you've got all this information there, you can output it to a hidden div with a control, or inspect it directly with something like xdebug and netbeans.
On a general note - if you have a large application which you wish to debug, it's really worth spending a bit of time investigating breakpoints, and interactive debugging - it's not so complex to setup and extremely useful. I asked about this recently, and it's really helped me with this kind of stuff!
If your database calls aren't abstracted (shame!) then you can override core PHP functions to include a debug call as demonstrated in this useful example on the PHP site, using the APD extension. Very useful! For example, you can override mysql_query()
with your own code to log the query.