本文介紹了如何檢查 UPDATE mysqli 查詢是否正確執行?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這是我的情況:
$sql = 'UPDATE user SET password = ? WHERE username = ? AND password = ?';
if($stmt->prepare($sql)) {
$stmt->bind_param('sss', $newPass, $_SESSION['username'], $oldPass);
$stmt->execute();
}
現在,如何查看 UPDATE 查詢是否成功執行?更準確地說,我如何查看舊密碼和用戶名是否正確,以便我可以存儲新密碼?我試過這樣做:
Now, how can I see if the UPDATE query is successfully executed? And more precisely how can I see if the old password and username are correct so that I can store the new password? I've tried by doing this:
$res = $stmt->execute();
echo 'Result: '.$res;
但我總是得到:
Result: 1
即使舊密碼不正確.
推薦答案
不更新行的查詢不是錯誤條件.這只是一個沒有改變任何東西的成功查詢.要查看更新是否確實改變了任何內容,您必須使用 mysqli_affected_rows()
A query which updates no rows is NOT an error condition. It's simply a succesful query that didn't change anything. To see if an update actually did change anything, you have to use mysqli_affected_rows()
這篇關于如何檢查 UPDATE mysqli 查詢是否正確執行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!