Why Does My Query With Named Parameters Return A Blank Result?
I am converting my MySQL code over to PDO to take advantage of prepared statements. I was originally getting a fatal error as described in this question. I had solved that issue,
Solution 1:
When using parameter through a array, you are binding with the default parameter type PDO::PARAM_STR
Dependending on the datatype:
- The MySQL timestamp data-type: it's the same, you'll pass it as a string
- The PHP Unix timestamp, which is an integer: you'll pass it an int.
I suggest you change your code like this:
$foo_query=$DBH->prepare(
"SELECT id, postdate, title, SUBSTRING_INDEX(body,' ',20) as preview_text, body
FROM BarTable WHERE postdate = :postdate
ORDER BY postdate DESC");
$foo_query->bindParam (
":postdate", strtotime ( $_REQUEST['postdate']), PDO::PARAM_INT);
// ^^^ bind as integer
$foo_query->execute();
Post a Comment for "Why Does My Query With Named Parameters Return A Blank Result?"