2012-10-05 42 views
0

我遇到了我從一個PHP腳本調用的mysqli查詢的問題。我已經多次重寫並且不斷收到錯誤:「mysqli num_rows命令不同步;現在無法運行此命令」這是第一次嘗試從此頁面訪問數據庫。我以前綁定的參數,然後調用:$ checkAcct-> num_rows()並獲得相同的問題。我也嘗試了某人在本網站的其他帖子中建議的內容: do {$ checkAcct-> use_result(); } while($ checkAcct-> next_result()); 但這也沒有工作,我得到了同樣的錯誤。在確定具有這些詳細信息的用戶不在數據庫中後,我執行另一個查詢以將用戶的信息插入網站,但是我收到的錯誤消息與此查詢有關。讓我知道是否有助於查看其他查詢。獲取「mysqli num_rows命令不同步;你現在不能運行這個命令」在mysql查詢中的錯誤

下面是我想使用的代碼:

$checkAcct = $dbConn->stmt_init(); 
$existingAcct = array(); 

if ($checkAcct->prepare("select usrName, eAddy from usr where usrName = ? OR eAddy = ?")) 
{ 
    $checkAcct->bind_param("ss", $usr, $eml); 
    $checkAcct->execute(); 
    $checkAcct->bind_result($result); 
    while($checkAcct->fetch()) 
    { 
     $existingAcct[] = $result; 
    } 
    if ($existingAcct[0] != 0) 
    { 

     if ($usr == $inputs['usrName'] && $eml == $inputs['eAddy']) 
     { 
      $acctSetupErrors[] = "Someone with your username and email address already exists. Please use the forgot password form to reset your password";  
     } else if ($eml == $inputs['eAddy']) { 
      $acctSetupErrors[] = "Someone with your email address already exists. Please use the forgot password form to reset your password or setup an account with a different email address";  
     } else { 
      $acctSetupErrors[] = "Someone with your username already exists. Please choose a different username"; 
     } 
    } 

    $checkAcct->free_result(); 
    $checkAcct->close(); 

編輯

好吧。我嘗試了你的方式,它也沒有工作,所以我去尋找任何以前的數據庫調用。我發現在腳本中更高級的包含文件中的數據庫調用中有問題的查詢。有趣的是,它從來沒有引起任何其他問題,但現在我釋放了結果,它運作良好。感謝您的幫助。我沒有足夠的積分來表示它必須位於代碼上方的某個位置。

+0

而不是upvoting,你可以接受答案 – caitriona

+0

完成。我對此很陌生。謝謝! – blendergasket

回答

0

你可以改變上面這樣的代碼,看看你得到

$checkAcct = $dbConn->stmt_init(); 
$existingAcct = array(); 

if ($checkAcct->prepare("select usrName, eAddy from usr where usrName = ? OR eAddy = ?")) 
{ 
    $checkAcct->bind_param("ss", $usr, $eml); 
    $checkAcct->execute(); 
    $checkAcct->store_result(); 
    printf("Number of rows: %d.\n", $stmt->num_rows); 
    $checkAcct->free_result(); 
    $checkAcct->close(); 
} 

而且你能不能確保緩衝區準備再次使用它之前被清除。我希望在這個語句之前執行的其他查詢仍然在mysqli prepare語句緩衝區中處於活動狀態。

+0

謝謝。這是一個數據庫調用隱藏在包含文件中,我不認爲要檢查。 – blendergasket

相關問題