Postgresql查询的PHP PDO绑定时间变量

时间:2016-12-14 10:08:42

标签: php postgresql pdo

伙计们,我在调试时遇到了麻烦。请注意,在使用Elephant Postgresql测试查询后,我可以验证查询是否可以在间隔转换中移交字符串文字:

function get_most_popular_posts($dbh, $count = 10, $from = 0) {

try{
$option = strval($from);
$newfrom = $option.' seconds';
//var_dump($from);
$sql = 'WITH top_voted AS(
        SELECT COUNT(post_id), post_id FROM VotedBy GROUP BY post_id
        ), res AS (SELECT id AS pid, author AS username, title, 
        body AS content, posted AS time,
        coordX AS coorX, coordY AS coorY, COUNT FROM Posts, top_voted
        WHERE Posts.id = top_voted.post_id AND posted >= (current_timestamp - interval :newfrom))
        SELECT pid, username, title, content, time, coorx, coory FROM res ORDER BY COUNT DESC, time DESC LIMIT :count;';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':count', $count);
$stmt->bindParam(':newfrom', $newfrom);
$stmt->execute(); 
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
//var_dump($stmt);
//var_dump($result);
//var_dump($newfrom);

请帮忙。 Var_dumping绑定变量表明连接有效。

0 个答案:

没有答案