2020-05-23 21:47:15 +00:00
|
|
|
<?php
|
|
|
|
|
2020-06-08 15:52:58 +00:00
|
|
|
/**
|
|
|
|
* Class Database
|
|
|
|
*
|
|
|
|
* Class with all neccessary stuff for the Database connections.
|
|
|
|
*/
|
2020-05-23 21:47:15 +00:00
|
|
|
class Database
|
|
|
|
{
|
2020-06-03 22:15:06 +00:00
|
|
|
private static ?Database $instance = null;
|
|
|
|
private mysqli $conn;
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-06-03 22:15:06 +00:00
|
|
|
private string $servername = "192.168.0.30";
|
|
|
|
private string $username = "root";
|
|
|
|
private string $password = "1qayxsw2";
|
2020-06-06 11:48:12 +00:00
|
|
|
private string $dbname = "mediacenter";
|
2020-05-23 21:47:15 +00:00
|
|
|
|
|
|
|
// The db connection is established in the private constructor.
|
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
// Create connection
|
|
|
|
$this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
|
|
|
|
|
|
|
|
if ($this->conn->connect_errno) {
|
|
|
|
echo "connecton failed... nr: " . $this->conn->connect_errno . " -- " . $this->conn->connect_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:52:58 +00:00
|
|
|
/**
|
|
|
|
* get an instance of this database class
|
|
|
|
* (only possible way to retrieve an object)
|
|
|
|
*
|
|
|
|
* @return Database dbobject
|
|
|
|
*/
|
2020-05-23 21:47:15 +00:00
|
|
|
public static function getInstance()
|
|
|
|
{
|
|
|
|
if (!self::$instance) {
|
|
|
|
self::$instance = new Database();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:52:58 +00:00
|
|
|
/**
|
|
|
|
* get a connection instance of the database
|
|
|
|
*
|
|
|
|
* @return mysqli mysqli instance
|
|
|
|
*/
|
2020-05-23 21:47:15 +00:00
|
|
|
public function getConnection()
|
|
|
|
{
|
|
|
|
return $this->conn;
|
|
|
|
}
|
2020-06-03 22:15:06 +00:00
|
|
|
|
2020-06-08 15:52:58 +00:00
|
|
|
/**
|
|
|
|
* get name of current active database
|
|
|
|
* @return string name
|
|
|
|
*/
|
2020-06-03 22:15:06 +00:00
|
|
|
public function getDatabaseName(){
|
|
|
|
return $this->dbname;
|
|
|
|
}
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|