1

我想为我的类创建一个删除一条记录的方法,这里是源:

/* 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 组合。

4

1 回答 1

4

加入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;

}
于 2012-08-16T08:03:27.983 回答