1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-16 03:24:01 +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

@@ -13,8 +13,10 @@ abstract class SqlDb {
public string $error; // last error message
/** @var Result|bool */ protected $multi; // used for multiquery
/** Connect to server */
abstract function connect(string $server, string $username, string $password): bool;
/** Connect to server
* @return string error message
*/
abstract function attach(?string $server, string $username, string $password): string;
/** Quote string to use in SQL
* @return string escaped string enclosed in '

View File

@@ -8,16 +8,18 @@ if (extension_loaded('pdo')) {
/** Connect to server using DSN
* @param mixed[] $options
* @return string error message
*/
function dsn(string $dsn, string $username, string $password, array $options = array()): void {
function dsn(string $dsn, string $username, string $password, array $options = array()): string {
$options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_SILENT;
$options[\PDO::ATTR_STATEMENT_CLASS] = array('Adminer\PdoResult');
try {
$this->pdo = new \PDO($dsn, $username, $password, $options);
} catch (\Exception $ex) {
auth_error(h($ex->getMessage()));
return $ex->getMessage();
}
$this->server_info = @$this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
return '';
}
function quote(string $string): string {