2014-10-19 122 views
-1

這是我的代碼。我試圖讓accountId的價值返回並分配給$ accountId但我總是得到0返回。查詢很好,它返回我想要在PHP中的值我的管理員,但它不會在這裏返回它。你知道爲什麼嗎?Bind_Result始終返回0

$mysqli = new mysqli($SQLhost, $SQLusername, $SQLpassword, $SQLdatabase); 

    $stmt = $mysqli->prepare("SELECT accountId FROM Account WHERE accountUsername=? AND accountPassword=?"); 
    $stmt->bind_param('ss', $username,$password); 

    $stmt->execute(); 

    $stmt->bind_result($accountId); 

    $_SESSION['accountId'] = $accountId; 
+0

你能提供一些調試值嗎?回聲出行的數量和var_dump $ accountId – Ali 2014-10-19 20:22:15

+0

我加$ stmt-> fetch();它在最後工作 – 2014-10-19 20:31:43

回答

0

工作代碼:
$的mysqli =新的mysqli($ SQLHOST,$ SQLusername,$ SQLPASSWORD,$ SQLdatabase);

$stmt = $mysqli->prepare("SELECT accountId FROM Account WHERE accountUsername=? AND accountPassword=?"); 
    $stmt->bind_param('ss', $username,$password); 

    $stmt->execute(); 

    $stmt->bind_result($accountID); 

    $stmt -> fetch(); 

    $_SESSION['accountId'] = $accountID;