在mysql中,我有以下代码:
$row = mysql_fetch_assoc($query);
$dbactive = $row['active'];
if ($dbactive == 1){
...
}...
但我必须在我的项目中使用 mysqli。所以我尝试在下面更改它,但我不太正确。谁能帮我纠正mysqli中的以下语句,使其与上面的mysql语句相匹配?
更新:
我在 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;
}
}
}