2017-08-25 166 views
-1

這是我的代碼:PHP PDO準備更新語句,其中=

什麼,我試圖在這裏,我想更新users_email_verified行,其中emaii,密碼匹配valies +其中users_email_verified設置爲0 (不是1)。

0 =未驗證 1 =已驗證。

但是在我的代碼中沒有更新,但它應該是。

echo count($result);始終回顯0

沒有顯示錯誤。我的代碼有什麼問題?

+4

您需要執行才能獲取 – Qirel

回答

3

1.You需要執行第一$stmt->execute()),然後取計數$stmt->rowCount())。

2. UPDATE查詢在成功執行後不返回記錄,它只是返回受影響的行數。因此請使用rowCount()獲取受影響的行數。

檢查以下正確的代碼: -

$stmt = $conn->prepare("UPDATE site_users SET users_email_verified = :users_email_verified WHERE users_email = :users_email AND users_password = :users_password and users_email_verified = :users_email_not_verified "); 

$users_email_verified = 1; 
$users_email_not_verified = 0; 

$stmt->bindParam(':users_email_not_verified', $users_email_not_verified,PDO::PARAM_STR); 
$stmt->bindParam(':users_email_verified', $users_email_verified,PDO::PARAM_STR); 
$stmt->bindParam(':users_email',$_GET["email"],PDO::PARAM_STR); 
$stmt->bindParam(':users_password',$_GET["token"],PDO::PARAM_STR); 



// The next 2 lines are supposed to count total number of rows effected 

$stmt->execute(); 
$result = $stmt->rowCount(); 
echo $result;