在我的桌子PDO的异常删除不存在
id |name
1 | one
然后
$id = '2';
$sql=$this-con->query("delete from aTable WHERE id = '".$id."' ");
线将只是
/* Affected rows: 0 Found rows: 0 Warnings: 0 Duration for 1 query: 0.000 sec. */
即使有执行没有这样的ID 2
在桌子 。
我该如何设法防止这种情况,PHP
或SQL
。 因为在我的PHP我需要告诉用户,有没有这样的行,但如何抓住失踪行,不检查其第一槽定制code.Because:
if($sql){
// Tell user the row is deleted, but (in fact there is no such row with the id in the column)
}
else{
// there must be exception goes here
}
你明白我的意思吗?或者没有这种方式没有先定制检查?
你应该开始使用预处理语句 – DarkBee
@DarkBee,是的,我很使用它,这只是我创建来解释我的问题的简短快速片段。 –