<?php
session_start();
class Database {
    private $host = "localhost:3306";
    private $dbname = "gqdcvggs_imators-user";
    private $username = "gqdcvggs";
    private $password = "imators_onlyforcpanelmachineforallwebsite***#@&&*SECURITY";
    private $conn;

    public function connect() {
        try {
            $this->conn = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->username, $this->password);
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return $this->conn;
        } catch(PDOException $e) {
            echo "Connection failed: " . $e->getMessage();
            return null;
        }
    }

    public function verifyLogin($email, $password) {
        try {
            $stmt = $this->conn->prepare("SELECT * FROM utilisateurs WHERE email = :email LIMIT 1");
            $stmt->bindParam(":email", $email);
            $stmt->execute();
            
            if($stmt->rowCount() > 0) {
                $user = $stmt->fetch(PDO::FETCH_ASSOC);
                if(password_verify($password, $user['password'])) {
                    return $user;
                }
            }
            return false;
        } catch(PDOException $e) {
            return false;
        }
    }

    public function getUserSubscriptions($userId) {
        try {
            $stmt = $this->conn->prepare("SELECT academ, ohmypanel, something FROM utilisateurs WHERE id = :userId");
            $stmt->bindParam(":userId", $userId);
            $stmt->execute();
            return $stmt->fetch(PDO::FETCH_ASSOC);
        } catch(PDOException $e) {
            return false;
        }
    }
}
?>