Last active
March 15, 2018 00:59
-
-
Save avtehnik/a20b0ed0bdfe37ef2d9f959080937ff7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class mysqlisniffer extends \mysqli | |
{ | |
private $queries = []; | |
public function query($query, $resultmode = MYSQLI_STORE_RESULT) | |
{ | |
$this->queries[] = ['debug_backtrace' => array_map(function ($item) { | |
return [ | |
$item['file'] . ':' . $item['line'], | |
$item['class'] . '::' . $item['function'] . '()' | |
]; | |
}, debug_backtrace()), 'query' => $query]; | |
return parent::query($query, $resultmode); | |
} | |
private function printBackLog() | |
{ | |
echo '<pre>'; | |
print_r($this->queries); | |
echo '</pre>'; | |
} | |
public function __destruct() | |
{ | |
$this->printBackLog(); | |
} | |
} | |
$db = new mysqlisniffer(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment