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