PDO:更新不起作用,没有错误


PDO: Update does not work, no error

时间有点神秘:我得到了这个查询:

$stmt = 'update wp_term_relationships set term_taxonomy_id = :newID '.
        'where term_taxonomy_id= :oldID and object_id = :postID';
self::$stmtSetNewID = self::$dataBase->prepareStatement($stmt);
[...]
self::$stmtSetNewID->bindParam(':oldID', $oldCatID, PDO::PARAM_INT);
self::$stmtSetNewID->bindParam(':newID', $newCatID, PDO::PARAM_INT);
self::$stmtSetNewID->bindParam(':postID', $postID, PDO::PARAM_INT);
$result = self::$stmtSetNewID->execute();
$rowCount = self::$stmtSetNewID->rowCount();
echo $rowCount;

我尝试设置错误级别

$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

并输出可能的错误

var_dump(self::$stmtSetNewID->errorInfo());

并输出受影响行的计数(在上面代码的末尾)。没有错误,没有警告,什么都没有。 rowCount()返回 1,但数据库中的值保持不变。

对我来说,看起来PDO/数据库说一切正常,但事实并非如此

我很沮丧,非常感谢每一个提示!谢谢!

更新:

echo "'nPostID: $postID | oldID: $oldCatID ".
     "| newID: $newCatID | rowCount: $rowCount'n<br/>'n";

输出的值正确,$rowCount为 1:

PostID: 5432 | oldID: 3 | newID: 32 | rowCount: 1
PostID: 5435 | oldID: 3 | newID: 8 | rowCount: 1 

好的伙计们,明白了。很抱歉在我的愚蠢上浪费了你的时间。正如脚本所说,更新执行时没有错误。但是我在那之后在我的脚本中更新了帖子,这次更新覆盖了我的新集类别。