<?php
class Database {
    private $host = "51.178.131.16"; // Ise "localhost" hi rakhein
    private $username = "rihancsc_shivam";
    private $password = "Shivam@1924";
    private $db_name = "rihancsc_mobileshop";
    public $conn;

    public function getConnection() {
        $this->conn = null;

        // Error reporting ko band karein taaki hum error ko manually handle kar sakein
        mysqli_report(MYSQLI_REPORT_OFF);
        
        $this->conn = new mysqli($this->host, $this->username, $this->password, $this->db_name);

        // Agar connection fail hota hai to saaf error message dein
        if ($this->conn->connect_error) {
            http_response_code(503); // Service Unavailable
            die(json_encode([
                'success' => false,
                'message' => 'Database Connection Error: ' . $this->conn->connect_error
            ]));
        }
        
        $this->conn->set_charset("utf8");

        return $this->conn;
    }
}
?>
