$db = new Database();
$tag_id = $_POST['tag_id'];
if (!$db->query("select id from tags where id = $tag_id")->fetchArray()['id']) {
exit('Тег не найден');
}
$tag_names = array();
foreach ($db->query("select name from tag_names where tag_id = $tag_id")->fetchAll() as $name) {
array_push($tag_names, $name['name']);
}
$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']);
}