I have a query like this: (on Postgresql 8.4, PHP-fpm 5.3.10 (fpm-fcgi))
select * from users where now() - interval '2 minutes' < seenlast ORDER BY seenlast;
I would like to use PHP/PDO query, so:
$mymin=5; //this is a variable can be changed by $_GET
$query = $db_conn->prepare("select * from users where now() - interval ':myminute minutes' < seenlast ORDER BY seenlast");
$query->bindParm(":myminute",$mymin)
$query->execute;
This does't work, I cant find a way to pass the minutes($mymin) in a proper way. If I hardcode the timestuff everithing works, so the other part of the code must be correct.
I also tried:
$temp=$mymin." minutes";
$query = $db_conn->prepare("select * from users where now() - interval :myminute < seenlast ORDER BY seenlast");
$query->bindParm(":myminute",$temp)
I already saw this, didn't help
Intervals can be multiplied by numbers. So one approach to this is to prepare the statement saying interval '1 minute' * :myminutes
instead, passing the "myminutes" parameter as a simple integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With