Skip to content

Instantly share code, notes, and snippets.

@siran
Last active May 8, 2017
Embed
What would you like to do?
How to get complete sql query with values replaced in the placeholders (CakePHP 3.4)
<?php
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()
->select($myFields)
->where($conditions);
$ql = new myLog();
debug($ql->toStatement($datos));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment