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