<root>
<primes>
<prime>101</prime>
<prime>103</prime>
<prime>107</prime>
...
</primes>
</root>
То, что вы пытаетесь сделать - это не массив, а строка. Её надо сформировать заранее и записать уже сформированную одним вызовом SetText. SELECT ...
FROM `items`
WHERE `id` IN (
(SELECT `itemId`
FROM `tags_items`
WHERE `tagId` IN (SELECT `id` FROM `tags` WHERE `tag` = :word))
UNION
(SELECT `itemId`
FROM `styles_items`
WHERE `styleId` IN (SELECT `id` FROM `styles` WHERE `style` = :word))
UNION
(SELECT `itemId`
FROM `labels_items`
WHERE `labelId` IN (SELECT `id` FROM `labels` WHERE `label` = :word))
)
SELECT `c`.`id_category`, `c`.`name`, IFNULL(`p`.`count`, 0) AS `count`
FROM `category` AS `c`
LEFT JOIN (
SELECT `id_category`, COUNT(*) AS `count`
FROM `product`
GROUP BY `id_category`
) AS `p` ON `p`.`id_category` = `c`.`id_category`
либоSELECT `c`.`id_category`, `c`.`name`, IFNULL(`p`.`count`, 0) AS `count`
FROM (
SELECT `id_category`, COUNT(*) AS `count`
FROM `product`
GROUP BY `id_category`
) AS `p`
RIGHT JOIN `category` AS `c` ON `c`.`id_category` = `p`.`id_category`