File "read_single.php"
Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/courses/read_single.php
File size: 1.3 KiB (1332 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
// Suppress all error output to ensure clean JSON responses
error_reporting(0);
ini_set('display_errors', 0);
ob_start();
require_once '../../config/config.php';
// Clean any output buffer and set proper headers
ob_clean();
header('Content-Type: application/json');
try {
if (!isset($_GET['id']) || empty($_GET['id'])) {
echo json_encode([
"status" => "error",
"message" => "Course ID is required."
]);
exit;
}
$id = (int)$_GET['id'];
if ($id <= 0) {
echo json_encode([
"status" => "error",
"message" => "Invalid Course ID."
]);
exit;
}
$stmt = $pdo->prepare("SELECT * FROM courses WHERE course_id = ?");
$stmt->execute([$id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
echo json_encode([
"status" => "success",
"data" => $row
]);
} else {
echo json_encode([
"status" => "error",
"message" => "Course not found."
]);
}
} catch (Throwable $e) {
http_response_code(500);
echo json_encode([
"status" => "error",
"message" => "An error occurred while fetching course details."
]);
}
?>