在MySQL中我有下面這段代碼:如何從MySQL以下更改代碼的mysqli
$row = mysql_fetch_assoc($query);
$dbactive = $row['active'];
if ($dbactive == 1){
...
}...
但是我在我的項目中使用的mysqli。所以我試圖改變它下面,但我不完全正確。任何人都可以幫我糾正mysqli中的下面的語句,以便它匹配上面的mysql語句嗎?
UPDATE:
我的企圖的mysqli:
// don't use $mysqli->prepare here
$query = "SELECT TeacherForename, TeacherSurname, TeacherUsername, TeacherPassword, Active FROM Teacher WHERE TeacherUsername = ? AND TeacherPassword = ? LIMIT 1";
// prepare query
$stmt=$mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("ss",$teacherusername,$teacherpassword);
// execute query
$stmt->execute();
// get result and assign variables (prefix with db)
$stmt->bind_result($dbTeacherForename,$dbTeacherSurname,$dbTeacherUsername,$dbTeacherPassword, $dbActive);
while($stmt->fetch()) {
if ($teacherusername == $dbTeacherUsername && $teacherpassword == $dbTeacherPassword) {
if ($dbActive == 1){
$loggedIn = true;
}
}
}
我已經更新代碼,我沒有測試它,但你覺得代碼以上是正確的還是會導致問題? – user1394925 2012-08-10 14:34:47
@ user1517628你不需要第二個'bind_result()'。您已經在第一次調用中將結果綁定到'$ dbactive'並傳遞了多個變量。 – Matt 2012-08-10 14:37:58
抱歉,第二次綁定的結果是我不小心忘了在更新之前將它從代碼中刪除。我會測試它,看看會發生什麼:) – user1394925 2012-08-10 14:42:06