0

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?

4
  • 3
    Why would you need that? Those are (tmp) log files - not a diary :) can you please elaborate? Commented 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. Commented 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. Commented 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. Commented Feb 19, 2014 at 13:02

1 Answer 1

1

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'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.