PDO和准备好的声明

时间:2013-11-04 13:30:26

标签: pdo

我正在尝试实施此查询:

SELECT AVG(timediff(end, start)) AS avg_in FROM phone_call
WHERE user_id=2
AND direction = 'o'
AND DATE(start) = DATE('2013-11-04 17:11:37')

使用PDO和PHP。你能提供一些关于如何做到这一点的建议。我试过了:

$uid = 2; $direction='o'; $date='2013-11-04 17:11:37';


$q = "SELECT AVG(timediff(end, start)) AS avg_in FROM phone_call
                WHERE user_id = ?
                AND direction = ?
                AND DATE(start) = DATE(?))";
        $stmt = $this->pdo->prepare($q);
        $stmt->bindParam(1, $uid, PDO::PARAM_INT, 5);
        $stmt->bindParam(2, $direction, PDO::PARAM_STR, 1);
        $stmt->bindParam(3, $date, PDO::PARAM_STR, 20);

        $stmt->execute();

        $result = $stmt->fetch(PDO::FETCH_ASSOC);
        //$result = round($result,2);

        return $result;

但这失败了。

编辑:

客户代码:

$a = $call_log->getAvCallIn(2,'o','2013-11-04 17:11:37'); //
print '<pre>';print_r($a);

没有任何内容打印到屏幕上!

我怀疑是

AND DATE(start) = DATE(?))

有问题的查询的一部分?

0 个答案:

没有答案