pdo = Database::getInstance()->getPdo(); } public function create(int $userId, int $postId, string $content): int { $stmt = $this->pdo->prepare( 'INSERT INTO comments (user_id, post_id, content) VALUES (:user_id, :post_id, :content)' ); $stmt->execute(['user_id' => $userId, 'post_id' => $postId, 'content' => $content]); return (int) $this->pdo->lastInsertId(); } public function findByPostId(int $postId): array { $stmt = $this->pdo->prepare( 'SELECT comments.*, users.username FROM comments JOIN users ON comments.user_id = users.id WHERE comments.post_id = :post_id ORDER BY comments.created_at ASC' ); $stmt->execute(['post_id' => $postId]); return $stmt->fetchAll(); } }