show plain database query

Permalink
This is a bit of a noob question but is there a way to display what e.g. SQL-query C5 makes out of

$db->query("INSERT INTO someTable (bla, blubb) values (?, ?)", $data);


(or any other query)

?!

nerdess
View Replies: View Best Answer
guythomas replied on at Permalink Reply
guythomas
You can print the actual sql statements by setting the debug on the database object, like so:

$db= Loader::db();
 $db->setDebug(1);


-Guy
nerdess replied on at Permalink Reply
nerdess
Hmmm....

echo 'aaa';
$db = Loader::db();
$db->setDebug(1);
echo 'bbb';


If I add the above code it doesn't get to the second echo anymore and the system stops...if I comment it out it does. So something is wonky with this method!

Also, where would I see the SQL? In some log-file?

When I used to work with Zend_db I was able to use the __toString() method to see the query but that doesn't seem to work in C5... :-/
guythomas replied on at Permalink Reply
guythomas
Take a look here for more info:
http://www.concrete5.org/documentation/developers/system/database-c...

The method I described actually prints the statements to the screen. It looks like there is another method that will put it into a table on your dbase..

I don't know why its not working for you, maybe set the value as TRUE instead of 1? I'm just passing this along from memory, and may have screwed up the syntax.

-Guy
andrew replied on at Permalink Reply
andrew
This has actually changed in the latest version of concrete5. See my other message in this thread. I've updated the docs page just now to make this clearer.
andrew replied on at Permalink Best Answer Reply
andrew
Guy was right for versions of concrete5 before 5.5.0 but we changed the syntax a bit. Instead of running

$db = Loader::db();
$db->setDebug(true);


Just do this instead

Database::setDebug(true);


and

Database::setDebug(false);


to turn off SQL printing.

The reason this doesn't work the same is because in 5.5 and greater the object returned by Loader::db() is actually a different object than the concrete5 generic Database wrapper class.