<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Dotenv\Dotenv;
$env = Dotenv::createImmutable(dirname(__DIR__));
$env->safeLoad();
function get_db(){
    static $pdo = null;
    if ($pdo) return $pdo;
    $host = $_ENV['DB_HOST'] ?? '127.0.0.1';
    $db   = $_ENV['DB_NAME'] ?? 'atulyasolar';
    $user = $_ENV['DB_USER'] ?? 'root';
    $pass = $_ENV['DB_PASS'] ?? '';
    $dsn = "mysql:host=$host;dbname=$db;charset=utf8mb4";
    $opts = [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC];
    $pdo = new PDO($dsn, $user, $pass, $opts);
    return $pdo;
}
