<?php
require_once __DIR__ . '/config.php';

function billing_db(): mysqli
{
    static $conn = null;

    if ($conn instanceof mysqli) {
        return $conn;
    }

    mysqli_report(MYSQLI_REPORT_OFF);
    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);

    if ($conn->connect_errno) {
        die('Database connection failed: ' . htmlspecialchars($conn->connect_error));
    }

    $conn->set_charset('utf8mb4');
    return $conn;
}
