Is there a problem with api calls at the moment? Yesterday this worked fine, and now I get this.
also it takes ages to load a list view.
This is my php file:
<?php
require 'db.php';
header('Content-Type: application/json');
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
try {
// Base URLs for images
$baseUrlThumbs = 'https://www.tapijtcenter.be/media/producten/thumbs/';
// Dynamic or default parent value
$parent = isset($_GET['parent']) ? intval($_GET['parent']) : 234;
// SQL-query to fetch all fields where parent matches
$stmt = $pdo->prepare("
SELECT proTitel, proPicAantal, parent, proSamenstelling, proId
FROM gdc_cat_producten
WHERE parent = :parent
");
$stmt->bindValue(':parent', $parent, PDO::PARAM_INT);
$stmt->execute();
// Fetch results
$products = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if (isset($row['proPicAantal'])) {
// Convert proPicAantal string to array
$images = explode(';', $row['proPicAantal']);
$row['firstImage'] = !empty($images) ? $baseUrlThumbs . $row['proId'] . '/' . $images[0] : null; // First image with thumbs URL
$row['proPicAantal'] = array_map(function($image) use ($baseUrlThumbs, $row) {
return $baseUrlThumbs . $row['proId'] . '/' . $image;
}, $images);
} else {
error_log("proPicAantal is missing for product ID: " . $row['proId'], 3, '/path/to/error.log');
$row['firstImage'] = null;
$row['proPicAantal'] = [];
}
$products[] = $row;
}
// Handle no products found
if (empty($products)) {
echo json_encode([
'success' => true,
'products' => []
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
exit;
}
// Return the results as JSON
echo json_encode([
'success' => true,
'products' => $products
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
} catch (PDOException $e) {
// Error handling
error_log($e->getMessage(), 3, '/path/to/error.log');
echo json_encode([
'success' => false,
'error' => 'An internal error occurred.'
]);
}