Last active
May 8, 2017 15:27
-
-
Save siran/afeb1ca069500fd5566c4bb02dbc57e9 to your computer and use it in GitHub Desktop.
How to get complete sql query with values replaced in the placeholders (CakePHP 3.4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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