1 回答
TA贡献1883条经验 获得超3个赞
您没有说明错误消息是什么,但一个明显的错误是您使用的引号没有被转义。(另外,在查询开始时您有太多的引号( "((SELECT...) 因此您需要像这样转义查询中的引号
$stmt = $conn->prepare("
(SELECT \"Tablebrand1\" AS `brand`, CROSSREFERENCE as `code`
FROM Tablebrand1 WHERE CROSSREFERENCE = 'SAMSUNG A10')
UNION
(SELECT \"Tablebrand2\" AS `brand`, CROSSREFERENCE as `code`
FROM Tablebrand2 WHERE CROSSREFERENCE = 'SAMSUNG A10')
UNION
(SELECT \"Tablebrand3\" AS `brand`, CROSSREFERENCE as `code`
FROM Tablebrand3 WHERE CROSSREFERENCE = 'SAMSUNG A10');"
);
或者,您可以在查询中使用单引号,而不是像这样的双引号
$stmt = $conn->prepare("
(SELECT 'Tablebrand1' AS `brand`, CROSSREFERENCE as `code`
FROM Tablebrand1 WHERE CROSSREFERENCE = 'SAMSUNG A10')
UNION
(SELECT 'Tablebrand2' AS `brand`, CROSSREFERENCE as `code`
FROM Tablebrand2 WHERE CROSSREFERENCE = 'SAMSUNG A10')
UNION
(SELECT 'Tablebrand3' AS `brand`, CROSSREFERENCE as `code`
FROM Tablebrand3 WHERE CROSSREFERENCE = 'SAMSUNG A10');"
);
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报