<?php
header('Content-Type: application/json; charset=utf-8');

$conn = new mysqli('localhost', 'transubd', 'Tr@nsub2@24', 'transubd_gestionparc');
if ($conn->connect_error) {
    die(json_encode(['error' => $conn->connect_error]));
}

$tests = [];

// Test 1 : exact
$q1 = "SELECT Num_Parc, DateExp, EtatCtrl, Etat, DateEtat FROM bus WHERE Num_Parc = '6100'";
$r1 = $conn->query($q1);
$row1 = $r1 ? $r1->fetch_assoc() : null;
$tests['exact_6100'] = $row1 ? $row1 : 'NOT FOUND';

// Test 2 : LIKE
$q2 = "SELECT Num_Parc, DateExp, EtatCtrl, Etat, DateEtat FROM bus WHERE Num_Parc LIKE '%6100%'";
$r2 = $conn->query($q2);
$results2 = [];
if ($r2 && $r2->num_rows > 0) {
    while ($r = $r2->fetch_assoc()) {
        $results2[] = $r;
    }
}
$tests['like_6100'] = !empty($results2) ? $results2 : 'NOT FOUND';

// Test 3 : Tous les bus (10 premiers)
$q3 = "SELECT Num_Parc FROM bus LIMIT 10";
$r3 = $conn->query($q3);
$results3 = [];
if ($r3 && $r3->num_rows > 0) {
    while ($r = $r3->fetch_assoc()) {
        $results3[] = $r['Num_Parc'];
    }
}
$tests['first_10_buses'] = $results3;

// Test 4 : Encodage du numéro
$tests['url_encoded'] = urlencode('6100');
$tests['trim_test'] = trim(' 6100 ');

echo json_encode($tests, JSON_PRETTY_PRINT);
$conn->close();