Reputation: 237
I want to create a method for my class that deleting one record, here is the source:
/* 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();
}
}
And I want that this function returns me an identifier of just removed record instead of standart TRUE/FALSE combination.
Upvotes: 1
Views: 2810
Reputation: 60536
Add return $idn
in the function?
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;
}
Upvotes: 4