<?php
/**
 * Database Configuration
 * For cPanel: Add your prefix (e.g., weavqqpf_Weaver)
 */
define('DB_HOST', '127.0.0.1');
define('DB_NAME', 'weaversm');
define('DB_USER', 'weaverdev');
define('DB_PASS', 'WeaverDev1!');
define('DB_CHARSET', 'utf8mb4');

function getDBConnection() {
    static $pdo = null;
    if ($pdo === null) {
        try {
            $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET;
            $pdo = new PDO($dsn, 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) {
            error_log("Database Error: " . $e->getMessage());
            die("Database connection failed.");
        }
    }
    return $pdo;
}
