This question already has an answer here:
I am passing a DELETE
query to mysql using PDO
statements. I want to know, whether the query really deletes a row or not? I try to use return value of $stmt->execute()
function delete(){
$stmt = $this->db->prepare("DELETE FROM users WHERE id= :id");
$stmt->bindValue(':id',$_POST[id]);
var_dump($stmt->execute());
}
But This gives always true
, even no row is deleted. This gives true even if I don't post any value Or even post same value again and again. May be because query is successful with 0 row deleted , so return value of $stmt->execute()
does not help.
So Is There any other way in PDO
to know whether any row is really deleted or not, more specifically I want to be sure that only one row was deleted.
So i want something like this
function delete(){
$stmt = $this->db->prepare("DELETE FROM users WHERE id= :id");
$stmt->bindValue(':id',$_POST[id]);
$stmt->execute();
if($rowdeleted == 1){ echo "success";}
else{echo "failure";}
}
Any ideas?
</div>