Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the raw SQL query string from the ORM

Tags:

cakephp-3.0

How do I get the raw SQL string sent to the server from the ORM? How do I intercept it in order to do custom work?

I want to forward the query to a custom driver. My target is MS SQL Server via NodeJS - from a Linux environment.

But I don't want to reinvent the wheel. I want to reuse the existing SqlServer query builder.

like image 231
Robert Sundström Avatar asked Oct 31 '25 10:10

Robert Sundström


1 Answers

As long as your query is not executed by toArray() or something similar, you can use $q->sql() to retrieve the raw sql query that cakePHP will execute:

$q = $this->Model->find('all');
$this->log($q->sql()); // log raw sql query
like image 92
Melvin Avatar answered Nov 03 '25 01:11

Melvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!