提问人:Karl Gadd 提问时间:11/16/2023 最后编辑:Karl Gadd 更新时间:11/16/2023 访问量:33
SQLSTATE[HY000]: 常规错误: -1310 [Microsoft][ODBC Microsoft 访问驱动程序] 对象无效或不再设置
SQLSTATE[HY000]: General error: -1310 [Microsoft][ODBC Microsoft Access Driver] Object invalid or no longer set
问:
总的来说,我是使用 PDO 和 php 的初学者,我很快就没有头发可以为此拔出汗毛了。
一直在调试,似乎找不到此错误背后的原因。谁能发现我的错误?
基本上,我正在尝试在同一提交表单中更新两个表。我似乎成功地将索引 .php 中的所有数据传递到我的更新.php,但我无法在同一提交中执行两个语句。我已经指出了错误发生在我的第一个.如果我注释掉我的第二个表的内容,它就可以工作,但我无法弄清楚为什么。$stmt->execute();
这也是我第一次像这样向 StackOverflow 提交编码问题,所以如果我遗漏了任何内容,请告诉我!:)
完整错误代码:SQLSTATE[HY000]: General error: -1310 [Microsoft][ODBC Microsoft Access Driver] Object invalid or no longer set. (SQLExecute[-1310] at ext\pdo_odbc\odbc_stmt.c:263) Code: HY000
update-inc.php
try {
require_once "dbh-inc.php"; //Get db connection
//echo '<script> var message = "update-inc: "+'.json_encode($postId).'; alert(message);</script>';
// ------- QUERY HERE --------
$query ="";
$oeId=0;
foreach($postId as $key=>$value){
$tempQuery ="";
$tempQuery2 ="";
${"t".$key} = "UPDATE ". $mainTable . " SET";
if($value != null){
${"t".$key} .= " Title = :newTitle".$key .",";
}
$tempQuery .= ${"t".$key};
if($value != null){
${"t".$key} = $tempQuery . " CopyText = :newText".$key;
}
${"t".$key} .= " WHERE id = :id". $key ."; ";
$tempQuery2 .= ${"t".$key};
$query = $tempQuery2;
if($oeId < 1){
$oeQuery = 'UPDATE '. $opEnTable .' SET
opening = :newOpening, ending = :newEnding
WHERE id = :oeId;';
$stmt = $dbh->prepare($oeQuery);
$stmt->bindValue(':oeId', $opEnId[$oeId], PDO::PARAM_INT);
$stmt->bindValue(':newOpening', $newOpening[$opEnId], PDO::PARAM_STR);
$stmt->bindValue(':newEnding', $newEnding[$opEnId], PDO::PARAM_STR);
echo "I'm getting here";
$stmt->execute();
// but not here
$stmt->closeCursor();
$oeId++;
}
$stmt = $dbh->prepare($query);
if($newTitle != null){
$stmt->bindValue(':newTitle'.$key, $newTitle[$key]);
}
if($newText != null){
$stmt->bindValue(':newText'.$key, $newText[$key]);
}
$stmt->bindValue(':id'.$key, $key);
//echo '<script> alert("query: '.$query.'\nkey: '.$key.'\n\nnewTitle: '.$newTitle[$key].'");</script>';
$stmt->execute();
$db = null;
$stmt = null;
}
dbh-inc.php
<?php
$dbStr = 'C:\xampp\htdocs\QuickCopy\QC1.accdb';
$mainTable = "main";
$opEnTable = "openingEnding";
if( !file_exists($dbStr) ){
die("Could not find database file.");
}
$dsn = 'odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};
DBQ='.$dbStr.';';
try {
$dbh = new PDO($dsn);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
答: 暂无答案
评论