Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Adminer dev
### Plugins
- Method afterQuery() to profile the queries

## Adminer 6.2.0 (released 2026-10-23)
- Use the page font instead of monospace in <code> except SQL
- Keep the leading newline of values in <textarea>
Expand Down
10 changes: 10 additions & 0 deletions adminer/drivers/mysql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ function next_result() {
return self::more_results() && parent::next_result(); // triggers E_STRICT on PHP < 7.4 otherwise
}

function query($query, int $result_mode = MYSQLI_STORE_RESULT) {
$start = microtime(true);
return query_done($query, $start, parent::query($query, $result_mode));
}

function multi_query($query) {
$start = microtime(true);
return query_done($query, $start, parent::multi_query($query));
}

function quote(string $string): string {
return "'" . $this->escape_string($string) . "'";
}
Expand Down
2 changes: 2 additions & 0 deletions adminer/drivers/pgsql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function close(): void {
}

function query(string $query, bool $unbuffered = false) {
$start = microtime(true);
if (self::$untrusted) {
// the extended protocol doesn't allow multiple commands, the transaction doesn't allow modifying data
$result = (@pg_query($this->link, "BEGIN READ ONLY")
Expand All @@ -87,6 +88,7 @@ function query(string $query, bool $unbuffered = false) {
} else {
$return = new Result($result);
}
query_done($query, $start, $return);
if (self::$untrusted) {
@pg_query($this->link, "COMMIT"); // rollbacks the transaction if the query failed
}
Expand Down
7 changes: 4 additions & 3 deletions adminer/drivers/sqlite.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ function attach(array $server, string $username, string $password): string {
}

function query(string $query, bool $unbuffered = false) {
$start = microtime(true);
$result = @$this->link->query($query);
$this->error = "";
if (!$result) {
$this->errno = $this->link->lastErrorCode();
$this->error = $this->link->lastErrorMsg();
return false;
return query_done($query, $start, false);
} elseif ($result->numColumns()) {
return new Result($result);
return query_done($query, $start, new Result($result));
}
$this->affected_rows = $this->link->changes();
return true;
return query_done($query, $start, true);
}

function quote(string $string): string {
Expand Down
7 changes: 7 additions & 0 deletions adminer/include/adminer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ function queryTimeout(): float {
function afterConnect(): void {
}

/** Called after each query sent to the database, e.g. to profile them
* @param float $time seconds the query took
* @param Result|bool $result
*/
function afterQuery(string $query, float $time, $result): void {
}

/** Headers to send before HTML output */
function headers(): void {
}
Expand Down
13 changes: 13 additions & 0 deletions adminer/include/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ function connection(?Db $connection2 = null) {
return ($connection2 ?: Db::$instance);
}

/** Report a finished query to plugins
* @param float $start output of microtime(true) before sending the query
* @param T $result
* @return T
* @template T
*/
function query_done(string $query, float $start, $result) {
if (Adminer::$instance) { // queries can be sent before plugins are loaded
adminer()->afterQuery($query, microtime(true) - $start, $result);
}
return $result;
}

/** Get Adminer object
* @return Adminer|Plugins
*/
Expand Down
5 changes: 3 additions & 2 deletions adminer/include/pdo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ function quote(string $string): string {
}

function query(string $query, bool $unbuffered = false) {
$start = microtime(true);
/** @var Result|bool */
$result = $this->pdo->query($query);
$this->error = "";
if (!$result) {
return $this->store_error(false);
return query_done($query, $start, $this->store_error(false));
}
$this->store_result($result);
return $result;
return query_done($query, $start, $result);
}

/** Store the last error of the connection if the operation failed */
Expand Down
Loading