abfrage der existenz der tabelle überarbeitet

This commit is contained in:
bernd 2021-03-03 18:08:00 +01:00
parent f1dafb3f4d
commit 436e869c21

View file

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