adminerevo/plugins/sql-log.php

42 lines
1 KiB
PHP
Raw Permalink Normal View History

2011-08-08 15:19:56 +00:00
<?php
2011-08-10 16:18:02 +00:00
/** Log all queries to SQL file (manual queries through SQL command are not logged)
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2017-02-27 12:43:33 +00:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 10:03:54 +00: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 15:19:56 +00:00
*/
class AdminerSqlLog {
2011-08-11 15:06:42 +00:00
/** @access protected */
2011-08-08 15:19:56 +00:00
var $filename;
/**
2011-08-10 16:10:23 +00:00
* @param string defaults to "$database.sql"
2011-08-08 15:19:56 +00:00
*/
2015-08-15 15:04:21 +00:00
function __construct($filename = "") {
2011-08-08 15:19:56 +00:00
$this->filename = $filename;
}
function messageQuery($query, $time, $failed = false) {
2015-03-11 16:52:11 +00:00
$this->_log($query);
}
function sqlCommandQuery($query) {
$this->_log($query);
}
function _log($query) {
2011-08-10 16:10:23 +00:00
if ($this->filename == "") {
$adminer = adminer();
$this->filename = $adminer->database() . ".sql"; // no database goes to ".sql" to avoid collisions
}
2011-08-08 15:19:56 +00:00
$fp = fopen($this->filename, "a");
flock($fp, LOCK_EX);
fwrite($fp, $query);
fwrite($fp, "\n\n");
flock($fp, LOCK_UN);
fclose($fp);
}
}