diff --git a/src/installer/pages/3.php b/src/installer/pages/3.php index 658477a..b399ce0 100644 --- a/src/installer/pages/3.php +++ b/src/installer/pages/3.php @@ -43,6 +43,13 @@ if (!empty($_POST)) { // try to connect only if dbconfig is defined if (isset($dbconfig)) { try { + // Enable DB exceptions instead of silent fails + $dbconfig += [ + "option" => [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + ] + ]; + $db = new Medoo($dbconfig); $sqlfiles = []; diff --git a/src/private/php/Utils/DatabaseUtils.php b/src/private/php/Utils/DatabaseUtils.php index 5073d8e..07ea3c8 100644 --- a/src/private/php/Utils/DatabaseUtils.php +++ b/src/private/php/Utils/DatabaseUtils.php @@ -2,6 +2,7 @@ namespace Wruczek\TSWebsite\Utils; use Medoo\Medoo; +use PDO; use Wruczek\TSWebsite\Config; /** @@ -28,7 +29,16 @@ class DatabaseUtils { public function getDb() { if($this->db === null) { try { - $db = new Medoo($this->configUtils->getDatabaseConfig()); + $config = $this->configUtils->getDatabaseConfig(); + + // Enable DB exceptions instead of silent fails + $config += [ + "option" => [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + ] + ]; + + $db = new Medoo($config); } catch (\Exception $e) { TemplateUtils::i()->renderErrorTemplate("DB error", "Connection to database failed", $e->getMessage()); exit;