abfrage der existenz der tabelle überarbeitet
This commit is contained in:
parent
f1dafb3f4d
commit
436e869c21
19
lib/db.php
19
lib/db.php
|
@ -112,9 +112,12 @@ class Database {
|
||||||
$this->pdo = $pdo;
|
$this->pdo = $pdo;
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
$this->log->d("Databaseobject successfull created");
|
$this->log->d("Databaseobject successfull created");
|
||||||
if ($this->TableExists() === false) {
|
try {
|
||||||
$this->log->n("No table requests found. Try to create table");
|
if ($this->TableExists() === false) {
|
||||||
$this->createTable();
|
$this->createTable();
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->log->e("Database exception: {$e->getMessage()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -128,13 +131,20 @@ class Database {
|
||||||
* eine Weiche anlegen?
|
* eine Weiche anlegen?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$this->log->d("Check if table requests exists");
|
||||||
$stmt = "SELECT * FROM information_schema.tables WHERE
|
$stmt = "SELECT * FROM information_schema.tables WHERE
|
||||||
table_type = 'BASE TABLE' and
|
table_type = 'BASE TABLE' and
|
||||||
table_name = 'requests'";
|
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) {
|
if ($response->rowCount() === 0) {
|
||||||
|
$this->log->n("No table requests found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$this->log->d("Table requests found");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +154,7 @@ class Database {
|
||||||
* Erstellt die Tabelle Requests.
|
* Erstellt die Tabelle Requests.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$this->log->n("try to create table requests");
|
||||||
$stmt = "CREATE TABLE IF NOT EXISTS requests (
|
$stmt = "CREATE TABLE IF NOT EXISTS requests (
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
nick varchar(80) NOT NULL UNIQUE,
|
nick varchar(80) NOT NULL UNIQUE,
|
||||||
|
|
Loading…
Reference in a new issue