<?php
// config/database.php - Database Connection

class Database {
    private $host = 'localhost';
    private $db_name = 'sharings_admob_manager';
    private $user = 'sharings_aleee_ahmed';
    private $password = 'unlockme109901';
    private $pdo;

    public function connect() {
        $this->pdo = null;

        try {
            $this->pdo = new PDO(
                'mysql:host=' . $this->host . ';dbname=' . $this->db_name,
                $this->user,
                $this->password
            );
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            echo json_encode(['error' => 'Database Connection Error: ' . $e->getMessage()]);
            exit;
        }

        return $this->pdo;
    }

    public static function getInstance() {
        static $instance = null;
        if ($instance === null) {
            $instance = new self();
            $instance->connect();
        }
        return $instance->pdo;
    }
}

?>