Trupti
Trupti

Reputation: 973

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

Upvotes: 0

Views: 318

Answers (1)

ascsoftw
ascsoftw

Reputation: 3476

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.

Upvotes: 1

Related Questions