【发布时间】:2010-01-03 21:37:37
【问题描述】:
好的,所以我一直在为我正在进行的项目使用PDO wrapper,并且我正在尝试确定 DELETE 查询是否成功。这是我正在使用的代码:
/**
* A pretty straight-forward query to delete a row from the verification
* table where user_id is $user_id and code is $code
*/
$result = $this->database->query("DELETE FROM verification " .
"WHERE user_id = %u AND code = %s",
$user_id,
$code);
/**
* This function will grab the PDO's exec() return, which should
* return the number of rows modified.
*/
if($this->database->getNumAffected($result) > 0)
return true;
else
return false;
问题是,无论DELETE查询是否真的删除了一行,$this->database->getNumAffected($result)总是返回'0'。
您可以查看包装器,但基本上 $this->database->getNumAffected($result) 返回的值与 PDO::exec() 将返回的值完全相同。
我在没有包装器的情况下尝试了这段代码(直接进入 PDO),我遇到了同样的问题,但反过来:它总是返回 '1'(无论是否删除了一行。)
任何帮助将不胜感激。
编辑:基于this SO 问题,我做的一切都是正确的......我不明白为什么这不起作用。
【问题讨论】: