I'm using CakePHP 2.3 with the debug kit plugin and I need print a commentary after each Sql query in my logs. Is it possible modify it?
-
3Why would you need that? Those are (tmp) log files - not a diary :) can you please elaborate?mark– mark2014-02-19 11:41:18 +00:00Commented Feb 19, 2014 at 11:41
-
I would have to do this to explain what happens in the database and add other queries that have not been done as an example.adriaroca– adriaroca2014-02-19 11:55:12 +00:00Commented Feb 19, 2014 at 11:55
-
The queries in that log represent all queries done in that specific request. What do you mean by adding other queries? You can only add queries by simply executing them, via CakePHP's model methods.linkyndy– linkyndy2014-02-19 12:29:50 +00:00Commented Feb 19, 2014 at 12:29
-
It is for external reader logs. The goal is to add commands, variables ... before and after the queries. I have a solution, if it works I write here.adriaroca– adriaroca2014-02-19 13:02:35 +00:00Commented Feb 19, 2014 at 13:02
Add a comment
|
1 Answer
To solve the problem, I created an instance of Mysql in Model/Datasource called DboCustomSource. Here I have overwritten the function execute of DboSource to modify the variable $sql.
App::uses('Mysql', 'Model/Datasource/Database');
class DboCustomSource extends Mysql{
public function execute($sql, $options = array(), $params = array()){
$sql .= 'comment';
return parent::execute($sql, $options, $params);
}
}
It's necessary to modify datasource in database's configuration: 'datasource' => 'DboCustomSource'.