这是我的try语句
$query = "DELETEh FROM supers WHERE id = :id";
try {
$stmt = $conn->prepare($query);
$stmt->bindValue(':id', $id);
$stmt->execute();
$_SESSION['notification'] = "Hero was deleted sucessfully";
}
这是其余的代码
catch(PDOException $e) {
$_SESSION['notification'] = "There was an error deleting hero: " . $e->getMessage();
}
header("Location: notification.php");
exit;
运行此命令时,它告诉我英雄已成功删除,即使不是因为删除后还有多余的“ h”也没有成功。谁能解释为什么这没进入陷阱区?
答案 0 :(得分:1)
很可能您没有这么做
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
打开PDO连接时。默认值为PDO::ERRMODE_SILENT
。 $conn->prepare()
将返回FALSE
,您需要从$conn->errorCode()
或$conn->errorInfo()
中获取原因。