<?php
// Database configuration
$host = 'localhost';
$db   = 'OOH';
$user = 'sa';
$pass = 'ntha';

$dsn = "sqlsrv:Server=$host;Database=$db";
$options = [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];

if (!function_exists('getPDO')) {
    function getPDO() {
        global $dsn, $user, $pass, $options;
        try {
            $pdo = new PDO($dsn, $user, $pass, $options);
            $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
            return $pdo;
        } catch (PDOException $e) {
            error_log("Database connection failed: " . $e->getMessage(), 3, __DIR__ . '/db_error.log');
            return null;
        }
    }
}
return getPDO();
?>
