|
|
<?php |
|
|
|
|
|
require_once 'config.php'; |
|
|
|
|
|
header('Access-Control-Allow-Origin: *'); |
|
|
header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); |
|
|
header('Access-Control-Allow-Headers: Content-Type'); |
|
|
|
|
|
try { |
|
|
$pdo = getDBConnection(); |
|
|
|
|
|
|
|
|
$stmt = $pdo->query("SELECT * FROM vehicles ORDER BY created_at DESC"); |
|
|
$vehicles = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
|
|
echo json_encode(['success' => true, 'data' => $vehicles]); |
|
|
} catch(PDOException $e) { |
|
|
echo json_encode(['success' => false, 'message' => 'Error fetching vehicles: ' . $e->getMessage()]); |
|
|
} |
|
|
?> |