Skip to content

Instantly share code, notes, and snippets.

Last active May 8, 2017
What would you like to do?
How to get complete sql query with values replaced in the placeholders (CakePHP 3.4)
use Cake\Database\Log\QueryLogger;
use Cake\ORM\Query;
class myLog extends QueryLogger
public function toStatement(Query $query)
$sql = $query->sql();
$bindings = $query->valueBinder()->bindings();
foreach ($bindings as $k => $value) {
$params[$value['placeholder']] = $value['value'];
$query->params = $params;
$query->query = $sql;
if (!empty($query->params)) {
$query->query = $this->_interpolate($query);
return $query->query;
$datos = $MyModel->find()
$ql = new myLog();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment