Summary Files Commits Branches @commit @diff @stats
path: root / src / models / DB.php
diff options
context:
space:
mode:
Commiteee825eb3ed35268c647a0e50904197eb2e953c5 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-03-31 21:40:34 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-03-31 21:40:34 +0300
Files7a0ad17631bb755401ea11b6501026d954c436ac /src/models/DB.php
devrix-job-board-eee825eb3ed35268c647a0e50904197eb2e953c5.tar
devrix-job-board-eee825eb3ed35268c647a0e50904197eb2e953c5.tar.gz
devrix-job-board-eee825eb3ed35268c647a0e50904197eb2e953c5.zip
Parent067e78d5d64adbf52c911f0f65cdaa7f8156e903 (diff)
Added JobOffer model and implemented a basic system for creating tables
1 files changed, 27 insertions, 0 deletions
-rw-r--r--src/models/DB.php27
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 @@
<?php
+include_once("JobOffer.php");
+
class DB {
private static $servername = "localhost";
private static $username = "root";
private static $password = "password";
private static $dbname = "devrix_job_board";
+ public const STRING_TYPE = "VARCHAR(100)";
+ public const FLOAT_TYPE = "DOUBLE(16,4)";
+ public const INTEGER_TYPE = "INT";
+
private $connection;
function __construct() {
@@ -23,9 +29,30 @@ class DB {
// Make the actual connection to the database
mysqli_select_db($this->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));
+ }
+ }
}