我正在尝试使用 odbc 连接和 php 从访问数据库中的表中提取数据。我已经编写了下面的代码,但它给出了错误“未捕获的异常 'com_exception' 和消息 '来源: Microsoft OLE DB Provider for ODBC Drivers
描述: [Microsoft] [ODBC Microsoft Access Driver] 查询表达式中的语法错误(缺少运算符)'table1 .col_date"
<?php $cn = new com("ADODB.Connection");
$rs = new com("ADODB.Recordset");
$cn->open("dsn=odbcconnection");
?>
<form action = "thispage.php" method = "post">
Enter Date : <input type = "text" name = "datadate" />
<input type = "submit" name = "submit" value = "submit" />
</form>
<?php
$datadate = isset($_REQUEST['datadate']) ? $_REQUEST['datadate'] : null; ?>
<?php $sql = "select col_date, sum(qty1), sum(qty2) from table1
where table1.col_date = '".$datadate."'
group by col_date
order by col_date";
// Execute query
$rs = $cn->execute($sql);
我认为只有参数行 table1.col_date = $datadate 存在问题,因为当我将 $datadate 替换为像 table1.col_date = #05/08/2012# 这样的静态日期时,它会正确显示日期的输出