是否有可能返回上次删除的记录ID?
我想为我的类中的方法,删除一条记录,这里是源:是否有可能返回上次删除的记录ID?
/* Delete One Record
* in @param (string) $tbl - name of the table
* in @param (int) $idn - id of record
* @return (int) - identifier of removed record
*/
public function DelOne($tbl,(int)$idn)
{
if ($result = $this->pdo->prepare("DELETE FROM `".$tbl."` WHERE `id`=:idn"))
{
$result->bindValue(":idn",$idn,PDO::PARAM_INT);
$result->execute();
}
}
而且我想,这个函数返回我刚删除的记录,而不是非标准TRUE/FALSE组合的标识符。
在功能添加return $idn
?
public function DelOne($tbl,(int)$idn)
{
if ($result = $this->pdo->prepare("DELETE FROM `".$tbl."` WHERE `id`=:idn"))
{
$result->bindValue(":idn",$idn,PDO::PARAM_INT);
// if all is well, return $idn
if($result->execute()) return $idn;
}
// if we are here, something was wrong
return false;
}
@VictorCzechov我们都有,当我们不能认为简单的东西x的时刻) – 2012-08-16 08:09:50
好吧,这是很奇怪,但如果与ID行= 2不存在了它反正返回我2。所以如何使这样,如果该行未被删除,它会返回我FALSE? – 2012-08-16 08:31:24
@VictorCzechov你可以使用'SELECT COUNT()WHERE ID ='添加一个检查。 – 2012-08-16 08:34:00
Y不能你只返回$ IDN? – Karma 2012-08-16 08:02:34