简体   繁体   中英

How to get sql query in cakePHP

I am using cakephp framework. I need SQL for following statement:

$vehicle = $this->Vehicle->find('all');

How can I do that?

Please guide me.

Thank you, Trupti

For Cakephp 1.x, you could use following code to get the last query

    $dbo = $this->Vehicle->getDatasource();
    $logs = $dbo->getLog();
    $lastLog = end($logs['log']);
    echo $lastLog['query'];

Alternatively, To get all the Queries executed in the Current HTTP Request, you can use the following code

$db =& ConnectionManager::getDataSource('default');
$db->showLog();

You have to set the Debug Mode to 2 for this to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM