PDO执行函数是否仅限于接受参数?

发布于 2024-10-22 08:22:47 字数 449 浏览 2 评论 0原文

我有一个工作 pdo 集成数据库类。我的所有查询都非常有效地工作,但是当我尝试传递某个值时,我陷入了困境。该值是:

DATE_SUB('2010-11-03', INTERVAL 30 DAY)

现在,我的类查询工作已准备就绪,如下所示:

SELECT DATE(added) AS date FROM data WHERE DATE(added) <= ?

当我尝试传递值时:DATE_SUB('2010-11-03', INETRVAL 30 DAY)execute () 函数,没有收到结果(但查询执行成功)。

我尝试发送原始值“2010-11-03”。它工作正常,但不支持此功能。 有人知道这个 mysql 函数没有被传递给执行函数吗?

I have a working pdo integrated database class. All of my queries are working very efficiently but when I try to pass a certain value, I got stuck. This value is:

DATE_SUB('2010-11-03', INTERVAL 30 DAY)

Now after all my working of class query is prepared like:

SELECT DATE(added) AS date FROM data WHERE DATE(added) <= ?

When i m trying to pass the value: DATE_SUB('2010-11-03', INETRVAL 30 DAY) to execute() function,no result is received(but query is executing successfully).

i tried sending raw value '2010-11-03'. Its working correctly but not wid this function.
Do anybody know y this mysql function is not being passed to execute function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若有似无的小暗淡 2024-10-29 08:22:47

您不能使用占位符来替换我的 SQL 查询的这一部分:占位符及其相应的绑定值只能对应于值。

当您传递 2010-11-03 时,您正在传递一个值 - 所以它可以工作。

当您尝试传递 DATE_SUB('2010-11-03', INTERVAL 30 DAY) 时,它不是一个值 - 所以它不起作用。

在这里,您必须重写您的Prepared语句,因此占位符对应于日期,而不是整个表达式:

SELECT DATE(added) AS date 
FROM data 
WHERE DATE(added) <= DATE_SUB(?, INTERVAL 30 DAY)

(如果需要,30也可以替换为占位符)

You cannot use placeholders as a replace this portion of my SQL query : placeholders and their corresponding bound values, can only correspond to values.

When you're passing 2010-11-03, you're passing a value -- so it works.

When you're trying to pass DATE_SUB('2010-11-03', INTERVAL 30 DAY), it's not a value -- so it doesn't work.

Here, you'll have to rewrite your Prepared statement, so the placeholder corresponds to the date, and not a whole expression :

SELECT DATE(added) AS date 
FROM data 
WHERE DATE(added) <= DATE_SUB(?, INTERVAL 30 DAY)

(The 30 could also be replaced with a placeholder, if needed)

飘逸的'云 2024-10-29 08:22:47
SELECT DATE(added) AS date 
  FROM data 
 WHERE DATE(added) <= DATE_SUB(?, INTERVAL ? DAY)

并将日期和间隔视为绑定值

SELECT DATE(added) AS date 
  FROM data 
 WHERE DATE(added) <= DATE_SUB(?, INTERVAL ? DAY)

and treat both the date and interval as bind values

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文