From f5084da2d211cb3e555be2e3acb2df1f06bdaf67 Mon Sep 17 00:00:00 2001 From: michalsn Date: Fri, 3 Jul 2020 13:43:29 +0200 Subject: [PATCH] Fix for getting database error. Fixes #3204 --- system/Database/BaseConnection.php | 25 +++++++------------------ system/Database/ConnectionInterface.php | 2 +- system/Model.php | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index ee6ab394f679..e1c4f7a0eaf7 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -373,12 +373,12 @@ public function initialize() $this->connectTime = microtime(true); - try + try { // Connect to the database and set the connection ID $this->connID = $this->connect($this->pConnect); - } - catch (\Throwable $e) + } + catch (\Throwable $e) { log_message('error', 'Error connecting to the database: ' . $e->getMessage()); } @@ -401,14 +401,14 @@ public function initialize() } } - try + try { // Try to connect $this->connID = $this->connect($this->pConnect); - } - catch (\Throwable $e) + } + catch (\Throwable $e) { - log_message('error', 'Error connecting to the database: '.$e->getMessage()); + log_message('error', 'Error connecting to the database: ' . $e->getMessage()); } // If a connection is made break the foreach loop @@ -557,17 +557,6 @@ public function getPrefix(): string //-------------------------------------------------------------------- - /** - * Returns the last error encountered by this connection. - * - * @return mixed - */ - public function getError() - { - } - - //-------------------------------------------------------------------- - /** * The name of the platform in use (MySQLi, mssql, etc) * diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index dffa5f335aaa..2df836e0c96b 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -124,7 +124,7 @@ public function getDatabase(): string; * * @return mixed */ - public function getError(); + public function error(): array; //-------------------------------------------------------------------- diff --git a/system/Model.php b/system/Model.php index 5d8aa86298ee..dda2b6f400cb 100644 --- a/system/Model.php +++ b/system/Model.php @@ -1334,7 +1334,7 @@ public function errors(bool $forceDB = false) } // Still here? Grab the database-specific error, if any. - $error = $this->db->getError(); + $error = $this->db->error(); return $error['message'] ?? null; }