Files
marmeladenladen/logic/getProductData.php
2022-05-23 09:26:57 +02:00

35 lines
943 B
PHP

<?php
getData();
function getData()
{
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
$sql = "SELECT `product_id`, `name`, `price`, `description`, `stock`, `weight`, `image`, `category`, `created_at` FROM `products`";
$stmt = $db->prepare($sql);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($product_id, $name, $price, $description, $stock, $weight, $image, $category, $created_at);
$data = array();
while ($stmt->fetch()) {
$data[] = array(
'product_id' => $product_id,
'name' => $name,
'price' => $price,
'description' => $description,
'stock' => $stock,
'weight' => $weight,
'image' => $image,
'category' => $category,
'created_at' => $created_at
);
}
$data = json_encode($data);
$stmt->close();
$db->close();
echo $data;
}
?>