Throw DB exceptions instead of silently failing

This commit is contained in:
Wruczek 2019-01-30 15:59:55 +01:00
parent 5e5fb356c7
commit d4f1efe96a
2 changed files with 18 additions and 1 deletions

View File

@ -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 = [];

View File

@ -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;