Files
adminer/plugins/sql-log.php

47 lines
1.4 KiB
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
*/
2025-04-07 16:32:57 +02:00
class AdminerSqlLog extends Adminer\Plugin {
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
*/
2025-04-08 13:14:32 +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-04-15 22:47:48 +02:00
$this->filename = Adminer\adminer()->database() . ($_GET["ns"] != "" ? ".$_GET[ns]" : "") . ".sql"; // no database goes to ".sql" to avoid collisions
2011-08-10 18:10:23 +02:00
}
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);
}
protected $translations = array(
'cs' => array('' => 'Zaznamenává všechny příkazy do souboru SQL'),
'de' => array('' => 'Protokollieren Sie alle Abfragen in einer SQL-Datei'),
'pl' => array('' => 'Rejestruj wszystkie zapytania do pliku SQL'),
'ro' => array('' => 'Logați toate interogările în fișierul SQL'),
'ja' => array('' => '全クエリを SQL ファイルに記録'),
);
2011-08-08 17:19:56 +02:00
}