我收到了以下PDO声明:
$myquery = SELECT * FROM DATABASE WHERE TABLE(Date) > 2014-04-07
$stmt = $this->pdo->prepare($myquery);
$stmt->execute();
我收到以下错误:
操作数类型冲突:日期与int
不兼容
如何比较PDO中的日期?
答案 0 :(得分:1)
比较时用单引号括住日期:
$myquery = "SELECT * FROM DATABASE WHERE TABLE(Date) > '2014-04-07'";
答案 1 :(得分:0)
我会这样尝试:
$myquery = SELECT * FROM table WHERE Date > ?
$stmt = $this->pdo->prepare($myquery,array('2014-04-07'));
$stmt->execute();
更好的是日期的非字符串,即datetime-object