connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); if ($this->connection->connect_error) { throw new Exception("Connection failed: " . $this->connection->connect_error); } $this->connection->set_charset("utf8mb4"); } catch (Exception $e) { die("Database connection failed: " . $e->getMessage()); } } public static function getInstance() { if (!self::$instance) { self::$instance = new Database(); } return self::$instance; } public function query($sql) { return $this->connection->query($sql); } public function prepare($sql) { return $this->connection->prepare($sql); } public function escape($value) { return $this->connection->real_escape_string($value); } public function getLastError() { return $this->connection->error; } public function getLastInsertId() { return $this->connection->insert_id; } public function getConnection() { return $this->connection; } }