<?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;
}
?>