39 lines
843 B
PHP
39 lines
843 B
PHP
<?php
|
|
|
|
class Database {
|
|
|
|
private static $db = null; // Singleton-Instanz
|
|
private $mysqli; // echte DB-Verbindung
|
|
|
|
// Konstruktor private → kann nur innerhalb der Klasse aufgerufen werden
|
|
private function __construct() {
|
|
|
|
$this->mysqli = new mysqli(
|
|
DB_CONNECTION,
|
|
DB_USER,
|
|
DB_PASS,
|
|
DB_DBNAME,
|
|
DB_PORT
|
|
);
|
|
|
|
if ($this->mysqli->connect_error) {
|
|
die("MySQL Connection Error: " . $this->mysqli->connect_error);
|
|
}
|
|
}
|
|
|
|
// Singleton-Zugriff
|
|
public static function getInstance() {
|
|
|
|
if (self::$db === null) {
|
|
self::$db = new Database();
|
|
}
|
|
|
|
return self::$db;
|
|
}
|
|
|
|
// Zugriff auf MySQLi
|
|
public function getConnection() {
|
|
return $this->mysqli;
|
|
}
|
|
}
|