$files = array_map('basename', glob($imagesFolder . "*.webp"));
ALTER TABLE `comment` ADD FOREIGN KEY (`id_parent`)
REFERENCES `comment` (id)
ON DELETE CASCADE
ON UPDATE CASCADE
Ответ MySQL: Документация
#1452 - Cannot add or update a child row: a foreign key constraint fails (`poseti`.`#sql-20c8_24c`, CONSTRAINT `comment_ibfk_3` FOREIGN KEY (`id_parent`) REFERENCES `comment` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
ALTER TABLE `comment` ADD FOREIGN KEY (`id`) REFERENCES `comment`(`id_parent`) ON DELETE CASCADE ON UPDATE RESTRICT;
Cannot add or update a child row: a foreign key constraint fails (`е1`.`#sql-20c8_1f6`, CONSTRAINT `comment_ibfk_3` FOREIGN KEY (`id`) REFERENCES `comment` (`id_parent`) ON DELETE CASCADE ON UPDATE RESTRICT)
и там уже сравнивать есть ли похожие элементы