gpt4 book ai didi

php - 参数编号无效,联合选择

转载 作者:行者123 更新时间:2023-11-29 13:26:31 24 4
gpt4 key购买 nike

我真的无法在这里发现我的错误。

$query = <<<'BUM'
(
SELECT ca.id, ca.name, ca.slug, ca.record_date, 2 AS complete, 0 AS numbers
FROM `cms_articles_article` ca
WHERE record_date
BETWEEN ':y_1 - :m_1 -01'
AND ':y_2 - :m_2 -31'
GROUP BY ca.id
LIMIT 0, 3)
UNION ALL (
SELECT ca.id, ca.name, ca.slug, ca.record_date, 1 AS complete, COUNT( ca.id ) AS numbers
FROM `cms_articles_article` ca
WHERE YEAR( record_date ) = :y_3
GROUP BY MONTH( record_date )
)
UNION ALL (
SELECT ca.id, ca.name, ca.slug, ca.record_date, 0 AS complete, COUNT( ca.id ) AS numbers
FROM `cms_articles_article` ca
GROUP BY YEAR( record_date )
)
ORDER BY
complete ASC,
record_date DESC
BUM;

$stmt = $db
->prepare($query)
;
$year = 2013;
$month = 12;
$stmt->execute(array(
':y_1' => $year,
':y_2' => $year,
':y_3' => $year,
':m_1' => $month,
':m_2' => $month,
));

我考虑到了你不能重用命名参数的事实。如果从查询(和执行)中删除 :y_3,它将正确运行。如有任何帮助,我们将不胜感激。

最佳答案

不能在字符串内使用参数。

':y_2 - :m_2 -31' -- 只是一个字符串,0个参数

您的整个查询只有 1 个参数。

, :y_2 - :m_2 -31 -- 是表达式,2个参数

关于php - 参数编号无效,联合选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20060419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com