<?php
// EasyStream Database Class
if (!defined("_ISVALID")) { exit; }

class DB {
    private $pdo;
    
    public function __construct() {
        try {
            $this->pdo = new PDO(
                "mysql:host=db;dbname=easystream;charset=utf8mb4",
                "easystream",
                "easystream",
                [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
            );
        } catch (PDOException $e) {
            die("Database connection failed: " . $e->getMessage());
        }
    }
    
    public function Execute($query, $params = []) {
        $stmt = $this->pdo->prepare($query);
        $stmt->execute($params);
        return $stmt;
    }
    
    public function GetRow($query, $params = []) {
        $stmt = $this->Execute($query, $params);
        return $stmt->fetch(PDO::FETCH_ASSOC);
    }
    
    public function GetAll($query, $params = []) {
        $stmt = $this->Execute($query, $params);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
}

$db = new DB();
?>