我有这样的查询:(在 Postgresql 8.4,PHP-fpm 5.3.10 (fpm-fcgi) 上)
select * from users where now() - interval '2 minutes' < seenlast ORDER BY seenlast;
我想使用 PHP/PDO 查询,所以:
$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;
这不起作用,我找不到以适当方式通过分钟($mymin)的方法。如果我对时间进行硬编码,一切正常,那么代码的另一部分必须是正确的。
我也试过:
$temp=$mymin." minutes";
$query = $db_conn->prepare("select * from users where now() - interval :myminute < seenlast ORDER BY seenlast");
$query->bindParm(":myminute",$temp)