Files
adminer/plugins/sql-log.php

40 lines
1001 B
PHP
Raw Normal View History

2011-08-08 17:19:56 +02:00
<?php
2025-03-24 23:49:30 +01:00
/** Log all queries to SQL file
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
/**
2025-03-28 07:06:34 +01:00
* @param string $filename 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
function messageQuery($query, $time, $failed = false) {
2025-03-11 07:56:28 +01:00
$this->log($query);
2015-03-11 17:52:11 +01:00
}
function sqlCommandQuery($query) {
2025-03-11 07:56:28 +01:00
$this->log($query);
2015-03-11 17:52:11 +01:00
}
2025-03-11 07:56:28 +01:00
private 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);
}
}