[英]delete query affected rows return greater then 0 either there is no record in DB
this is a piece of code 这是一段代码
public static function delete_ques($ques_id) {
$con = Connection::get_Connection();
$sql_delete = "DELETE FROM question WHERE ques_id = " . $ques_id;
$result_delete = $con->query($sql_delete);
if ($result_delete->rowCount()) {
$con->close();
echo 'hell not ';
return true;
} else {
$con->close();
echo 'hell yes';
return false;
}
}
i cannot figure it out why its happening 我不知道为什么会这样
The problem you are facing is because of rowCount() . 您面临的问题是因为rowCount() 。 according to php.net 根据php.net
rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object . rowCount()返回受相应PDOStatement对象执行的最后一个DELETE,INSERT或UPDATE语句影响的行数。
In your situation i would use affected_rows. 在您的情况下,我会使用受影响的行。 So you if-else code block would be like this 所以你if-else代码块会像这样
if ($con->affected_rows) {
$con->close();
echo 'hell not ';
return true;
} else {
$con->close();
echo 'hell yes';
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.