<?php
// Test script to verify environment variables are loaded in container
echo "=== Environment Variables Test ===\n";
echo "DB_HOST: " . (getenv('DB_HOST') ?: 'NOT SET') . "\n";
echo "DB_NAME: " . (getenv('DB_NAME') ?: 'NOT SET') . "\n";
echo "DB_USER: " . (getenv('DB_USER') ?: 'NOT SET') . "\n";
echo "DB_PASS: " . (getenv('DB_PASS') ? 'SET' : 'NOT SET') . "\n";
echo "FRONTEND_PORT: " . (getenv('FRONTEND_PORT') ?: 'NOT SET') . "\n";
echo "COMPANY_NAME: " . (getenv('COMPANY_NAME') ?: 'NOT SET') . "\n";

echo "\n=== Database Connection Test ===\n";
try {
    require_once 'backend/config/database.php';
    $db = new Database();
    $conn = $db->getConnection();
    echo "✅ Database connection successful!\n";
    
    // Test a simple query
    $stmt = $conn->query("SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = '" . getenv('DB_NAME') . "'");
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    echo "📊 Database contains " . $result['count'] . " tables\n";
    
} catch (Exception $e) {
    echo "❌ Database connection failed: " . $e->getMessage() . "\n";
}

echo "\n=== PHP Environment ===\n";
echo "PHP Version: " . phpversion() . "\n";
echo "Current Working Directory: " . getcwd() . "\n";
echo "Environment file exists (.env.local): " . (file_exists('.env.local') ? 'YES' : 'NO') . "\n";
echo "Environment file exists (.env): " . (file_exists('.env') ? 'YES' : 'NO') . "\n";
?>
