From eee825eb3ed35268c647a0e50904197eb2e953c5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 21:40:34 +0300 Subject: Added JobOffer model and implemented a basic system for creating tables --- src/models/DB.php | 27 +++++++++++++++++++++++++++ src/models/JobOffer.php | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/models/JobOffer.php (limited to 'src') diff --git a/src/models/DB.php b/src/models/DB.php index f6db512..1ca0137 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -1,10 +1,16 @@ connection, self::$dbname); + + $this->createTables(); + } + + private function createTables() { + $this->createTable(JobOffer::TABLE_NAME, JobOffer::TABLE_COLUMNS); } function __destruct() { mysqli_close($this->connection); } + + function createTable(string $tableName, array $columns) { + $query = "CREATE TABLE IF NOT EXISTS {$tableName}( + id INT NOT NULL AUTO_INCREMENT,"; + + foreach ($columns as $column) { + $query .= "{$column},"; + } + + $query .= "PRIMARY KEY (id));"; + + if (!mysqli_query($this->connection, $query)) { + die(mysqli_error($this->connection)); + } + } } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php new file mode 100644 index 0000000..1fb3d28 --- /dev/null +++ b/src/models/JobOffer.php @@ -0,0 +1,18 @@ +db = $db; + } +} -- cgit v1.3.1-26-gb76a