php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

How to implement SQL logs in a legacy project

Open garbinmarcelo opened this issue 2 years ago • 4 comments

Hello, would you know if I could do this to get the SQL queries in a legacy project? or even in pure mysql queries?

Currently Kohana v2 is used and in some controllers it is done: Database::instance()->query($query); to get insert, update, select and delete. The project does not use queries via Model.

SQL call examples:

Database::instance()->query("SELECT * FROM table WHERE id = {$this->id}")[0];

or

$this->db = new Database();
$this->db->select('*')->from('table')->where('id', $this->id)>get()->current();

Could someone guide me how can I implement SQL logs? It would be very important to me.

Thanks

garbinmarcelo avatar Jan 11 '23 10:01 garbinmarcelo

Any help with this issue? :grimacing:

garbinmarcelo avatar Jan 30 '23 12:01 garbinmarcelo

The biggest question is which database php backend is used, mysqli, pdo, mysql?

mx03 avatar Aug 20 '23 12:08 mx03

The biggest question is which database php backend is used, mysqli, pdo, mysql?

We use MariaDB

garbinmarcelo avatar Aug 21 '23 11:08 garbinmarcelo

Here is the MySQL Kohana/Database/MySQL.php

// Set the last query
$this->last_query = $sql;

With that, make a query collector, like this: DebugBar/DataCollector/PDO/PDOCollector.php Another examples: DebugBar/Bridge/DoctrineCollector.php DataCollector/QueryCollector.php koseven-debug-toolbar

parallels999 avatar Sep 18 '23 20:09 parallels999