From 436e869c21936842e5456b896c82f54474d1d65b Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 3 Mar 2021 18:08:00 +0100 Subject: [PATCH] =?UTF-8?q?abfrage=20der=20existenz=20der=20tabelle=20?= =?UTF-8?q?=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/db.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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,