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:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user