SQL Query在Microsoft Access上失败,处理MYSQL

时间:2014-08-01 04:24:45

标签: php database ms-access pdo

我试图通过执行此操作在Microsoft Access数据库上运行查询

$ticket_time = $db->prepare("SELECT problems.start_date,
                                    problems.rep,
                                    problems.id,
                                    tblusers.fname,
                                    tblnotes.id,
                                    tblnotes.note
                                    FROM problems
                                    RIGHT JOIN tblusers ON problems.rep = tblusers.sid
                                    RIGHT JOIN tblnotes ON problems.id = tblnotes.id
                                    WHERE `start_date` > '$history' 
                                    AND status BETWEEN 1 AND 8
                                    GROUP BY start_date
                                    ORDER BY start_date ASC");

$ticket_time->execute();
while ($row = $ticket_time->fetch(PDO::FETCH_ASSOC))
{
    //Do things
}

此查询在我连接到mysql数据库时有效,但生产数据库是Microsoft Access。连接到MS Access数据库时,同样的查询返回

Fatal error: Call to a member function execute() on a non-object on line 84

第84行为$ticket_time->execute();

var_dump($ticket_time);在连接到MS Access数据库时返回boolean false,但在连接到MYSQL数据库时按预期返回,这使我相信连接到MS时查询可能有问题访问数据库,但我不知道从哪里开始故障排除。

可能导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

首先,MS Access不支持反引号来描述列标识符,而是使用方括号,因此您必须更改

WHERE `start_date` > '$history'

WHERE [start_date] > '$history'

甚至

WHERE start_date > '$history'