<?php
session_start();
error_reporting(0);
header('content-type:application/json');
header("Access-Control-Allow-Origin: *");
class Database {
    private static $instance;
    private $connection;

    // Private constructor to prevent direct instantiation
    private function __construct() {
        // Initialize database connection here
        $this->connection = new mysqli('localhost', 'erp', 'JesusChristisLord', 'aurarich_erp');
        
        // Check connection
        if ($this->connection->connect_error) {
            die("Connection failed: " . $this->connection->connect_error);
        }
    }

    // Public method to get the instance of the class
    public static function getInstance() {
        if (!self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    // Public method to get the database connection
    public function getConnection() {
        return $this->connection;
    }

    // Prevent cloning of the instance
    private function __clone() {}

    // Prevent unserialization of the instance
    public function __wakeup() {}

    // Destructor to close the database connection if needed
    public function __destruct() {
        if ($this->connection) {
            $this->connection->close();
        }
    }
}

// To get the database connection instance
$db = Database::getInstance();
$business_conn = $db->getConnection();