<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

echo "Test 1: Script PHP exécuté\n";

try {
    echo "Test 2: Tentative de connexion PDO\n";
    
    $dbHost = 'serverkmaf.helioho.st';
    $dbName = 'kombarferd_gestpeseedb';
    $dbUser = 'kombarferd_dbadmin';
    $dbPass = 'dbadmin@2024';
    
    $dsn = "mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4";
    $pdo = new PDO($dsn, $dbUser, $dbPass, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ]);
    
    echo "Test 3: Connexion PDO réussie\n";
    
    $sql = "SELECT COUNT(*) as total FROM pesee";
    $stmt = $pdo->query($sql);
    $result = $stmt->fetch();
    
    echo "Test 4: Requête réussie - Total: " . $result['total'] . "\n";
    
    echo json_encode(['success' => true, 'total' => $result['total']]);
    
} catch (Exception $e) {
    echo "ERREUR: " . $e->getMessage() . "\n";
    echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
?>