Summary Files Commits Branches @commit @diff @stats
path: root / src / models / DB.php
diff options
context:
space:
mode:
Commit067e78d5d64adbf52c911f0f65cdaa7f8156e903 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-03-31 20:41:37 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-03-31 20:41:37 +0300
Filesa1e17351e2d93cf0fc1f523364bce3d1e9dbf4a5 /src/models/DB.php
devrix-job-board-067e78d5d64adbf52c911f0f65cdaa7f8156e903.tar
devrix-job-board-067e78d5d64adbf52c911f0f65cdaa7f8156e903.tar.gz
devrix-job-board-067e78d5d64adbf52c911f0f65cdaa7f8156e903.zip
Parentc56907d9d35255829b5e85c7f79e578269df55b8 (diff)
Added database initialisation to DB model; added a script for watching file changes
1 files changed, 31 insertions, 0 deletions
-rw-r--r--src/models/DB.php31
diff --git a/src/models/DB.php b/src/models/DB.php
new file mode 100644
index 0000000..f6db512
--- /dev/null
+++ b/src/models/DB.php
@@ -0,0 +1,31 @@
+<?php
+class DB {
+ private static $servername = "localhost";
+ private static $username = "root";
+ private static $password = "password";
+ private static $dbname = "devrix_job_board";
+
+ private $connection;
+
+ function __construct() {
+ $this->connection = mysqli_connect(self::$servername, self::$username, self::$password);
+
+ if (!$this->connection) {
+ die(mysqli_connect_error());
+ }
+
+ // Make sure the actual db exists
+ $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";";
+
+ if (!mysqli_query($this->connection, $createDBQuery)) {
+ die(mysqli_error($this->connection));
+ }
+
+ // Make the actual connection to the database
+ mysqli_select_db($this->connection, self::$dbname);
+ }
+
+ function __destruct() {
+ mysqli_close($this->connection);
+ }
+}