1
我試圖弄清楚如何驗證如果我成功地刪除了一行並在會話中存儲了一條消息,所以我認爲rowCount()將是一個很好的函數那,但它根本不返回任何東西。當我使用die()時,我只是得到一個空白屏幕。這是我的功能。獲取沒有返回值()
public function destroy($id)
{
$stmt = $this->connection->prepare('
DELETE FROM users WHERE id = :id
');
$stmt->bindParam(':id', $id);
$stmt->execute();
die($count = $stmt->rowCount()); // I get no return value or anythhing on this line
// It just gives me a blank screen whether I enter a
// valid id or not
$msg = new \Plasticbrain\FlashMessages\FlashMessages();
if (!session_id()) @session_start();
if($count){
$msg->success('User successfully deleted', 'index.php');
} else {
$msg->error('User ID not existing', 'index.php');
}
header("location:index.php");
}
要跟進@ YourCommonSense的答案,只需回顯計數,然後die()或簡單地退出; – FrankerZ