Print SQL query of ORM query builder in cakephp3

Fury picture Fury · Mar 18, 2016 · Viewed 17.1k times · Source

How to print ORM query

$query = $articles->find('all')->contain(['Comments']);

For example print =>

SELECT * FROM comments WHERE article_id IN (comments);

Answer

Yosyp Schwab picture Yosyp Schwab · Mar 18, 2016

Wrapping your ORM query result with the debug function will show the SQL and bound params:

debug($query);

You can also similarly look at the query results with the debug function.See CakePHP 3: retrieving data and result sets — Debugging Queries and ResultSets