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
(or any other query)
?!
$db->query("INSERT INTO someTable (bla, blubb) values (?, ?)", $data);
(or any other query)
?!
Hmmm....
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... :-/
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... :-/
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
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
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.
Guy was right for versions of concrete5 before 5.5.0 but we changed the syntax a bit. Instead of running
Just do this instead
and
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.
$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.
This has changed in concrete5 version 8. Can you give me the new syntax?
Thank you.
Thank you.
I would love to know what the syntax for Version 8 is as well.
I love Concrete5, but documentation has been severely lacking as of lately.
I love Concrete5, but documentation has been severely lacking as of lately.
Best I've found is:
http://stackoverflow.com/questions/4570608/how-to-debug-mysql-doctr... pointed me in the right direction.
\Database::get()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
http://stackoverflow.com/questions/4570608/how-to-debug-mysql-doctr... pointed me in the right direction.
How do you get the SQL query performed from that? Nothing in the buffer from ob_start() after issuing that.
There is a logging setting "Log Database Queries" at dashboard/system/environment/logging.
Then read the log at dashboard/system/optimization/query_log
Then read the log at dashboard/system/optimization/query_log
Aye but I gave up paging through all the queries generated for one page load 10 entries at a time....
Normally I'll turn on mysql logging and tail the logfile with code breakpoints but can't do that on a live server, esp when you don't have permissions to read mysql.general_log or edit the DB cnf file.
Normally I'll turn on mysql logging and tail the logfile with code breakpoints but can't do that on a live server, esp when you don't have permissions to read mysql.general_log or edit the DB cnf file.
Fyi https://www.concrete5.org/marketplace/addons/speed-analyzer/... (free) can also log queries and track how long execution time took.
V8.4.2
This gives me an error:
Whoops\Exception\ErrorException: call_user_func_array() expects parameter 1 to be a valid callback, class 'Concrete\Core\Database\Connection\Connection' does not have a method 'setDebug' in file /var/www/vhosts/demo-sp.redacted.com/httpdocs/updates/concrete5-8.4.2/concrete/src/Database/DatabaseManager.php on line 279
Stack trace back to my script is:
4. Concrete\Core\Support\Facade\Database->__callStatic() /var/www/vhosts/demo-sp.redacted.com/httpdocs/packages/redacted/controllers/single_page/ajax.php:281
Which is:
281 ob_start(); \Database::setDebug(true);
This gives me an error:
Whoops\Exception\ErrorException: call_user_func_array() expects parameter 1 to be a valid callback, class 'Concrete\Core\Database\Connection\Connection' does not have a method 'setDebug' in file /var/www/vhosts/demo-sp.redacted.com/httpdocs/updates/concrete5-8.4.2/concrete/src/Database/DatabaseManager.php on line 279
Stack trace back to my script is:
4. Concrete\Core\Support\Facade\Database->__callStatic() /var/www/vhosts/demo-sp.redacted.com/httpdocs/packages/redacted/controllers/single_page/ajax.php:281
Which is:
281 ob_start(); \Database::setDebug(true);
-Guy