Summary Files Commits Branches @commit @diff @stats
path: root / src / models / DB.php
blob: f6db512c673762951685fac5b1ee5dace7bcb5bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
	}
}