Skip to content

Commit e7ec27c

Browse files
committed
fix: Added a Fix for Checking if Connected or Not
1 parent 264407b commit e7ec27c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

webfiori/database/Database.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Database {
6969
*
7070
*/
7171
private $tablesArr;
72+
private $lastErr;
7273
/**
7374
* Creates new instance of the class.
7475
*
@@ -86,6 +87,10 @@ public function __construct(?ConnectionInfo $connectionInfo) {
8687
}
8788
$this->queries = [];
8889
$this->tablesArr = [];
90+
$this->lastErr = [
91+
'code' => 0,
92+
'message' => ''
93+
];
8994
}
9095
/**
9196
* Start SQL transaction.
@@ -408,16 +413,13 @@ public function getExecutedQueries() : array {
408413
*/
409414
public function getLastError() : array {
410415
if ($this->connection !== null) {
411-
return [
416+
$this->lastErr = [
412417
'message' => $this->connection->getLastErrMessage(),
413418
'code' => $this->connection->getLastErrCode()
414419
];
415420
}
416421

417-
return [
418-
'message' => '',
419-
'code' => 0
420-
];
422+
return $this->lastErr;
421423
}
422424
/**
423425
* Returns the last generated SQL query.
@@ -549,7 +551,15 @@ public function isConnected() : bool {
549551
if ($this->getConnectionInfo() === null) {
550552
return false;
551553
}
552-
if ($this->getConnection() === null) {
554+
try {
555+
if ($this->getConnection() === null) {
556+
return false;
557+
}
558+
} catch (DatabaseException $ex) {
559+
$this->lastErr = [
560+
'code' => $ex->getCode(),
561+
'message' => $ex->getMessage()
562+
];
553563
return false;
554564
}
555565

0 commit comments

Comments
 (0)