How to insert things like “now() -interval '2 minutes'” into PHP PDO query?

后端 未结 4 1195
无人共我
无人共我 2021-01-11 20:14

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 seen         


        
4条回答
  •  悲&欢浪女
    2021-01-11 20:54

    I have been struggling with Phalcon and its inner Models PDO parser for hours with the same problem.

    I found this solution:

    public static function getTimedoutRequests($secsThreshold) {
        return self::find(
            array(
                // PDO is buggy here, can't use INTERVAL
                "DATE_PART('epoch', create_time) < DATE_PART('epoch', NOW()) - ?0",
                "bind" => array(
                    $secsThreshold
                )
            )
        );
    }
    

提交回复
热议问题