1. 程式人生 > >PHP 使用 PDO 的 execute () 方法 刪除不存在的資料,返回值仍然是 true 是什麼鬼

PHP 使用 PDO 的 execute () 方法 刪除不存在的資料,返回值仍然是 true 是什麼鬼

$sql = 'DELETE FROM `article` WHERE `article_id` =:article_id AND `user_id` =:user_id';
        $stmt = $this->_db->prepare($sql);
        $stmt->bindParam(':article_id', $article_id);
        $stmt->bindParam(':user_id', $user_id);
        $stmt->execute(); // 當刪除的資料不存在時,這裡無論如何都返回 true ?
$row = $stmt->rowCount(); if ($row == 0) { throw new Exception('刪除失敗', ErrorCode::ARTICLE_DELETE_FAIL); }

所以, execute () 方法執行刪除操作,只能通過影響行數來判斷操作是否成功 ?