我整个早上都在做这个,我不知道为什么它不起作用。
$spn = '20275096';
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)}; Dbq=".realpath('exported/test1.mdb')."; Uid=Admin");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare(" SELECT Cup_PartUpdateCommodityID FROM Cup_PartUpdateCommodity
INNER JOIN Cup_PartUpdateInfo ON
[Cup_PartUpdateCommodity].Cup_PartUpdateCommodityID = [Cup_PartUpdateInfo].Cup_PartUpdateCommodityID
INNER JOIN Cup_PartUpdate ON
[Cup_PartUpdateInfo].Cup_PartUpdateID = [Cup_PartUpdate].Cup_PartUpdateID
WHERE [Cup_PartUpdate].PartNum = :partnum ");
$stmt->bindParam(':partnum', $spn);
$stmt->execute();
$row = $stmt->fetch();
echo $row['Cup_PartUpdateCommodityID'];
它抛出以下错误:
致命错误:未捕获的异常“PDOException”,带有消息“SQLSTATE [42000]:语法错误或访问冲突:-3100
[Microsoft][ODBC Microsoft Access Driver] 查询表达式中的语法错误(缺少运算符)“[Cup_PartUpdateCommodity].Cup_PartUpdateCommodityID = [Cup_PartUpdateInfo].Cup_PartUpdateCommodityID INNER JOIN Cup_PartUpdate ON [Cup_PartUpdateInfo].Cup_PartUpdateID = [Cup_PartUpdate].Cup_PartUpdateID”。(SQLExecute[-3100] at ext\pdo_odbc\odbc_stmt.c:254)' 在 C:\sites\myproject\test.php:31
堆栈跟踪:#0 C:\sites\myproject\test.php(31): PDOStatement->execute() #1 {main} 在第 31 行的 C:\sites\myproject\test.php 中抛出
注意:上面的代码将在一个需要 $spn 作为参数的函数中执行。就目前而言,我正在为 $spn 设置默认值。任何人?