diff --git a/lib/db.php b/lib/db.php index 92e2baa..d7359f1 100644 --- a/lib/db.php +++ b/lib/db.php @@ -112,9 +112,12 @@ class Database { $this->pdo = $pdo; $this->log = $log; $this->log->d("Databaseobject successfull created"); - if ($this->TableExists() === false) { - $this->log->n("No table requests found. Try to create table"); - $this->createTable(); + try { + if ($this->TableExists() === false) { + $this->createTable(); + } + } catch (Exception $e) { + $this->log->e("Database exception: {$e->getMessage()}"); } } @@ -128,13 +131,20 @@ class Database { * eine Weiche anlegen? */ + $this->log->d("Check if table requests exists"); $stmt = "SELECT * FROM information_schema.tables WHERE table_type = 'BASE TABLE' and table_name = 'requests'"; - $response = $this->pdo->query($stmt); + try { + $response = $this->pdo->query($stmt); + } catch (PDOException $e) { + throw new Exception($e->getMessage()); + } if ($response->rowCount() === 0) { + $this->log->n("No table requests found"); return false; } + $this->log->d("Table requests found"); return true; } @@ -144,6 +154,7 @@ class Database { * Erstellt die Tabelle Requests. */ + $this->log->n("try to create table requests"); $stmt = "CREATE TABLE IF NOT EXISTS requests ( id serial PRIMARY KEY, nick varchar(80) NOT NULL UNIQUE,