<?php
require_once __DIR__ . '/../config/config.php';

try {
    $pdo = new PDO("mysql:host=" . DB_HOST, DB_USER, DB_PASS);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = file_get_contents(__DIR__ . '/schema.sql');
    
    // Split SQL by semicolon to execute multiple statements if needed, 
    // but PDO::exec might handle it if the driver allows. 
    // Safest is to just run the whole block or split.
    // The schema has CREATE DATABASE and USE, so we need to run it carefully.
    
    $pdo->exec($sql);
    
    echo "Banco de dados inicializado com sucesso!";
} catch (PDOException $e) {
    echo "Erro ao inicializar banco de dados: " . $e->getMessage();
}
