File "read_by_student.php"
Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/enrollments/read_by_student.php
File size: 1.13 KiB (1157 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
// Clean JSON-only response
error_reporting(0);
ini_set('display_errors', 0);
ob_start();
require_once '../../config/config.php';
header('Content-Type: application/json');
try {
$student_id = isset($_GET['student_id']) ? (int)$_GET['student_id'] : 0;
$academic_year_id = isset($_GET['academic_year_id']) ? (int)$_GET['academic_year_id'] : 0;
$course_id = isset($_GET['course_id']) ? (int)$_GET['course_id'] : 0;
if ($student_id<=0 || $academic_year_id<=0 || $course_id<=0) {
echo json_encode([ 'status'=>'error', 'message'=>'Invalid parameters' ]);
exit;
}
$stmt = $pdo->prepare('SELECT * FROM student_enrollments WHERE student_id=? AND academic_year_id=? AND course_id=?');
$stmt->execute([$student_id, $academic_year_id, $course_id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
echo json_encode(['status'=>'success','data'=>$row]);
} else {
echo json_encode(['status'=>'success','data'=>null]);
}
} catch (Throwable $e) {
http_response_code(500);
echo json_encode(['status'=>'error','message'=>'Server error']);
}
?>