2011-08-08 17:19:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
2011-08-10 18:18:02 +02:00
|
|
|
/** Log all queries to SQL file (manual queries through SQL command are not logged)
|
2015-09-08 09:23:25 -07:00
|
|
|
* @link https://www.adminer.org/plugins/#use
|
2017-02-27 13:43:33 +01:00
|
|
|
* @author Jakub Vrana, https://www.vrana.cz/
|
2018-01-14 11:03:54 +01:00
|
|
|
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
|
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
2011-08-08 17:19:56 +02:00
|
|
|
*/
|
|
|
|
|
class AdminerSqlLog {
|
2025-03-11 07:21:13 +01:00
|
|
|
protected $filename;
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2011-08-08 17:19:56 +02:00
|
|
|
/**
|
2011-08-10 18:10:23 +02:00
|
|
|
* @param string defaults to "$database.sql"
|
2011-08-08 17:19:56 +02:00
|
|
|
*/
|
2015-08-15 17:04:21 +02:00
|
|
|
function __construct($filename = "") {
|
2011-08-08 17:19:56 +02:00
|
|
|
$this->filename = $filename;
|
|
|
|
|
}
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2018-02-01 13:12:05 +01:00
|
|
|
function messageQuery($query, $time, $failed = false) {
|
2015-03-11 17:52:11 +01:00
|
|
|
$this->_log($query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sqlCommandQuery($query) {
|
|
|
|
|
$this->_log($query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _log($query) {
|
2011-08-10 18:10:23 +02:00
|
|
|
if ($this->filename == "") {
|
2025-03-05 11:40:56 +01:00
|
|
|
$adminer = Adminer\adminer();
|
2011-08-10 18:10:23 +02:00
|
|
|
$this->filename = $adminer->database() . ".sql"; // no database goes to ".sql" to avoid collisions
|
|
|
|
|
}
|
2011-08-08 17:19:56 +02:00
|
|
|
$fp = fopen($this->filename, "a");
|
|
|
|
|
flock($fp, LOCK_EX);
|
|
|
|
|
fwrite($fp, $query);
|
|
|
|
|
fwrite($fp, "\n\n");
|
|
|
|
|
flock($fp, LOCK_UN);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
}
|
|
|
|
|
}
|