34567-vm/taxes/read.php
2025-10-02 20:43:00 +00:00

32 lines
781 B
PHP

<?php
require_once '../db/config.php';
header('Content-Type: application/json');
$id = $_GET['id'] ?? null;
try {
$pdo = db();
if ($id) {
$stmt = $pdo->prepare("SELECT * FROM taxes WHERE id = ?");
$stmt->execute([$id]);
$tax = $stmt->fetch(PDO::FETCH_ASSOC);
if ($tax) {
echo json_encode($tax);
} else {
http_response_code(404);
echo json_encode(['error' => 'Tax not found']);
}
} else {
$stmt = $pdo->query("SELECT * FROM taxes ORDER BY name");
$taxes = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($taxes);
}
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
}