<?php
// db.php - safe DB connection, no output to client
// Save this file as UTF-8 without BOM and do NOT include a closing PHP tag.

ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/error_log.txt');

// Turn off mysqli internal reporting so warnings are not emitted to output
mysqli_report(MYSQLI_REPORT_OFF);

// DB credentials
$DB_HOST = 'localhost';
$DB_USER = 'qmyctlgi_surveyor';
$DB_PASS = 'kF78Bzp@Ub8m2HK';
$DB_NAME = 'qmyctlgi_surveys';

// Create connection quietly and handle errors by logging only
$conn = @new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);

if (! $conn || $conn->connect_error) {
    error_log('DB connection failed: ' . ($conn ? $conn->connect_error : 'unknown'));
    $conn = null;
} else {
    // Ensure proper charset and log if it fails
    if (! $conn->set_charset('utf8mb4')) {
        error_log('Failed to set DB charset: ' . $conn->error);
    }
}
