1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-09 08:06:59 +02:00

Db: Unify connection error handling

This commit is contained in:
Jakub Vrana
2025-03-28 22:00:53 +01:00
parent d5bba383ea
commit 29339c5223
13 changed files with 95 additions and 123 deletions

View File

@@ -24,13 +24,10 @@ if (isset($_GET["imap"])) {
private $mailbox;
private $imap;
function connect(string $server, string $username, string $password): bool {
function attach(?string $server, string $username, string $password): string {
$this->mailbox = "{" . "$server:993/ssl}"; // Adminer disallows specifying privileged port in server name
$this->imap = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1);
if (!$this->imap) {
$this->error = imap_last_error();
}
return $this->imap;
return ($this->imap ? '' : imap_last_error());
}
function select_db(string $database): bool {
@@ -275,10 +272,7 @@ if (isset($_GET["imap"])) {
function connect($credentials) {
$connection = new Db;
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
return $connection;
}
return $connection->error;
return ($connection->attach($credentials[0], $credentials[1], $credentials[2]) ?: $connection);
}
function support($feature) {