本文介紹了如何檢查 UPDATE mysqli 查詢是否正確執(zhí)行?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
這是我的情況:
$sql = 'UPDATE user SET password = ? WHERE username = ? AND password = ?';
if($stmt->prepare($sql)) {
$stmt->bind_param('sss', $newPass, $_SESSION['username'], $oldPass);
$stmt->execute();
}
現(xiàn)在,如何查看 UPDATE 查詢是否成功執(zhí)行?更準(zhǔn)確地說,我如何查看舊密碼和用戶名是否正確,以便我可以存儲新密碼?我試過這樣做:
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
即使舊密碼不正確.
推薦答案
不更新行的查詢不是錯誤條件.這只是一個沒有改變?nèi)魏螙|西的成功查詢.要查看更新是否確實(shí)改變了任何內(nèi)容,您必須使用 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()
這篇關(guān)于如何檢查 UPDATE mysqli 查詢是否正確執(zhí)行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!