0

我正在尝试使用 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# 这样的静态日期时,它会正确显示日期的输出

4

1 回答 1

1

问题是您正在使用发布到当前页面的查询字符串参数是空的,或者您对 POST 感到困惑。尝试以下

如果您要发布到页面本身,请执行以下操作

<form action = "<?php echo $PHP_SELF; ?>" method = "post"> 

然后将其更改为以下内容:

$datadate = isset($_POST['datadate']) ? $_POST['datadate'] : null; ?>

最后如前所述进行更改

完全替换或删除括号[table1.col_date][table1].[col_date]尝试以下操作

<?php $sql = "select col_date, qty1, qty2 from table1 where  [table].[col_date]= '".$datadate."' group by col_date order by col_date"; 
于 2012-08-29T08:49:32.437 回答