<?php
// PDO connection for better error handling
$drHost = "localhost";
$drUser = "plus2exam2082";
$drPass = "plus2exam2082";
$drDb = "plus2exam2082";
try {
    // Create a PDO connection
    $conn = new PDO("mysql:host=$drHost;dbname=$drDb", $drUser, $drPass);
    
    // Set PDO to throw exceptions on error (this is crucial for catching errors)
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Optional: Disable emulation of prepared statements to use real prepared statements
    $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    // Optional: For testing purposes, you could check the connection (though errors will throw exceptions)
    // Uncomment below line if you want to confirm the connection
    // $conn->query("SELECT 1"); // Just a simple query to check connection

} catch (PDOException $connError) {
    // Catch and display any connection errors
    echo "Failed to connect: " . $connError->getMessage();
    exit();  // Stop the script in case of failure
}
?>
