$db = new Database();
$tag_id = $_POST['tag_id'];
$stmt = $db->prepare("SELECT `tag_names`.`name` FROM `tags` INNER JOIN `tag_names` ON `tags`.`id` = `tag_names`.`tag_id` WHERE `tags`.`id` = ?");
$stmt->execute([$tag_id]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($rows)<1) {
exit('Тег не найден');
}
$tag_names = array();
foreach ($rows as $row) {
array_push($tag_names, $row['name']);
}