<?php
/**
 * TechStackBase – Database Configuration
 * Uses PDO (MySQL)
 * Shared-hosting safe
 */

require_once __DIR__ . '/app.php';

/*
|--------------------------------------------------------------------------
| Database Credentials
|--------------------------------------------------------------------------
| NOTE: These are the credentials you already provided.
| We are only CONSUMING the existing database.
*/
define('DB_HOST', 'localhost');
define('DB_NAME', 'cuj011_jb26user');
define('DB_USER', 'cuj011_apijb26');
define('DB_PASS', 'ApiJB26user$');

/*
|--------------------------------------------------------------------------
| PDO Connection
|--------------------------------------------------------------------------
*/
try {
    $pdo = new PDO(
        'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8',
        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) {
    // Do NOT expose credentials or stack traces in production
    http_response_code(500);

    if (APP_ENV !== 'production') {
        echo json_encode([
            'status'  => 'error',
            'message' => 'Database connection failed',
            'detail'  => $e->getMessage()
        ]);
    } else {
        echo json_encode([
            'status'  => 'error',
            'message' => 'Database connection error'
        ]);
    }

    exit;
}
