开发者

is PDO execute function is limited to accept arguments?

开发者 https://www.devze.com 2023-02-18 12:49 出处:网络
I have a working pdo integrated database class. All of my queries are working very efficiently but when I try to pass a ce开发者_高级运维rtain value, I got stuck. This value is:

I have a working pdo integrated database class. All of my queries are working very efficiently but when I try to pass a ce开发者_高级运维rtain 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?


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)


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

and treat both the date and interval as bind values

0

精彩评论

暂无评论...
验证码 换一张
取 消