<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
} 

class Database {
    private $host = "localhost";
    private $db_name = "gbjpe_visitas";
    private $username = "gbjpe_root";
    private $password = "W;%TJS^GOid(";
    public $conn;

    public function getConnection() {
        $this->conn = null;
        try {
            $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, 
                                  $this->username, $this->password);
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->conn->exec("set names utf8");
        } catch(PDOException $exception) {
            echo "Error de conexión: " . $exception->getMessage();
        }
        return $this->conn;
    }
}

// Función para mostrar mensajes emergentes
function mostrarMensaje($tipo, $mensaje) {
    echo '<div class="alert alert-' . $tipo . ' alert-dismissible fade show" role="alert">
            ' . $mensaje . '
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
          </div>';
}
?>