Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see CakePHP's SQL dump in the controller?

Tags:

sql

cakephp

Is there a way that one can cause CakePHP to dump its SQL log on demand? I'd like to execute code up until a point in my controller and see what SQL has been run.

like image 536
Justin Avatar asked Sep 05 '10 17:09

Justin


People also ask

How can I get SQL query in cakephp?

$log = $this->User->getDataSource()->getLog(false, false); debug($log); This will show a log of all queries: $db =& ConnectionManager::getDataSource('default'); $db->showLog(); If you want to show all queries log all over the application you can use in view/element/filename.

How can I print last query in cakephp 3?

Add below code in app_model. php file which is located at root/cake/libs/model. Add below line in your model where you want print query. $last_query = $ this ->ModelName->getLastQuery();


1 Answers

Try this:

$log = $this->Model->getDataSource()->getLog(false, false); debug($log); 

http://api.cakephp.org/2.3/class-Model.html#_getDataSource

You will have to do this for each datasource if you have more than one though.

like image 139
deceze Avatar answered Sep 18 '22 09:09

deceze