init Abgabe
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user