<?php
/**
 * Database connection bootstrap.
 *
 * Provides two connections to the same database for compatibility with
 * existing code:
 *   - $conn : mysqli connection (used by legacy pages)
 *   - $pdo  : PDO connection with exceptions + utf8mb4 (used by the
 *             OTP / signup AJAX endpoints: send-otp.php, verify-otp.php)
 *
 * Assumption: DB host/user/password are unchanged from the original
 * configuration; only the database name has been updated to match the
 * provided schema dump (yqpqsjjj_dabil2).
 */

const DB_HOST = "localhost";
const DB_USER = "yqpqsjjj";
const DB_PASS = "O54-XvUyIqo*47";
const DB_NAME = "yqpqsjjj_dabil2";

// --- mysqli connection (legacy pages) ---
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$conn->set_charset("utf8mb4");

// --- PDO connection (OTP / signup flow) ---
try {
    $pdo = new PDO(
        "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4",
        DB_USER,
        DB_PASS,
        [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ]
    );
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}
