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?
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
30could also be replaced with a placeholder, if needed)