31 lines
964 B
PHP
31 lines
964 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once 'db/config.php';
|
|
|
|
$response = ['success' => false, 'message' => 'ID de producto no proporcionado.'];
|
|
|
|
if (isset($_GET['id'])) {
|
|
$product_id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
|
|
|
if ($product_id) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT id, nombre, sku FROM products WHERE id = :id");
|
|
$stmt->execute(['id' => $product_id]);
|
|
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($product) {
|
|
$response = ['success' => true, 'product' => $product];
|
|
} else {
|
|
$response['message'] = 'Producto no encontrado.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$response['message'] = 'Error en la base de datos: ' . $e->getMessage();
|
|
}
|
|
} else {
|
|
$response['message'] = 'ID de producto inválido.';
|
|
}
|
|
}
|
|
|
|
echo json_encode($response);
|
|
?>
|