从访问表中检索数据时,GROUP BY子句不起作用

时间:2015-07-08 19:05:46

标签: php ms-access odbc

这是我们需要运行的查询:

$dbname = 'demo';
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");
$result = $db->query('SELECT Table1.id,Table2.name,Table2.email,Table3.desc,Table1.ORDNUM,Table4.cust,Table4.Startdate,Table4.CNCLDATE,Table4.ship,Table1.qty,Table5.t5_NAME,Table5.t5_EMAIL,Table6.t6_NAME FROM (((((Table1 INNER JOIN Table4 on Table1.ORDNUM = Table4.ORDNUM)INNER JOIN Table2 on icust.CODE = Table4.CODE)inner join Table3 on Table4.TRMCODE = Table3.TRMCODE)inner join Table5 on Table5.t5_CODE = Table4.code)inner join Table6 on Table6.ID = Table4.div)' GROUP BY Table1.id);

Table1.id有很多可用的记录,所以我需要按Table1.id对它进行分组。但它无法完成。这是我收到的错误消息:

  

致命错误:在第***行的D:\ xampp \ htdocs \ Project \ Page.php中的非对象上调用成员函数fetch()

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您在GROUP BY子句之前有一个单引号可能导致错误。尝试在最后的结束括号之前移动它。

$dbname = 'demo';
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");
$result = $db->query('SELECT Table1.id,Table2.name,Table2.email,Table3.desc,Table1.ORDNUM,Table4.cust,Table4.Startdate,Table4.CNCLDATE,Table4.ship,Table1.qty,Table5.t5_NAME,Table5.t5_EMAIL,Table6.t6_NAME FROM (((((Table1 INNER JOIN Table4 on Table1.ORDNUM = Table4.ORDNUM)INNER JOIN Table2 on icust.CODE = Table4.CODE)inner join Table3 on Table4.TRMCODE = Table3.TRMCODE)inner join Table5 on Table5.t5_CODE = Table4.code)inner join Table6 on Table6.ID = Table4.div) GROUP BY Table1.id');