PDO执行函数是否仅限于接受参数?
我有一个工作 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用占位符来替换我的 SQL 查询的这一部分:占位符及其相应的绑定值只能对应于值。
当您传递
2010-11-03
时,您正在传递一个值 - 所以它可以工作。当您尝试传递
DATE_SUB('2010-11-03', INTERVAL 30 DAY)
时,它不是一个值 - 所以它不起作用。在这里,您必须重写您的Prepared语句,因此占位符对应于日期,而不是整个表达式:
(如果需要,
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 :
(The
30
could also be replaced with a placeholder, if needed)并将日期和间隔视为绑定值
and treat both the date and interval as bind values