Base Directory:
/home/ecedu/public_html/cce/service
View File: commentRead.php
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../Models/BasicManager.php';
try {
/* 1) الاتصال */
$pdo = (new BasicManager())->getDb();
$pdo->exec("SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci");
/* 2) جلب news_id بأمان */
$newsId = filter_input(INPUT_POST, 'news_id', FILTER_VALIDATE_INT, [
'options' => ['min_range' => 1]
]);
if (!$newsId) {
echo json_encode([], JSON_UNESCAPED_UNICODE);
exit;
}
/* 3) الاستعلام */
$stmt = $pdo->prepare("
SELECT comment_id,
parent_comment_id,
comment,
comment_sender_name,
comment_sender_email,
comment_at,
news_id
FROM dbs_comment
WHERE news_id = :nid
ORDER BY comment_at ASC
");
$stmt->bindValue(':nid', $newsId, PDO::PARAM_INT);
$stmt->execute();
/* 4) الإخراج */
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC), JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
}