我有代碼下面。當我使用此代碼而沒有WHERE
子句時,將按預期顯示錶中的所有用戶。但是,當使用WHERE
子句時,不顯示任何內容。mysqli不執行Select語句
可能是什麼原因,我該如何解決?
謝謝!
function requestUser($user) {
$DBHost = "localhost";
$DBUser = "dbUser";
$DBPass = "dbPass";
$DBName = "dbName";
$db = new mysqli($DBHost, $DBUser, $DBPass, $DBName);
if ($db -> connect_errno > 0) {
$lbOK = false;
}
else {
$lbOK = $db -> set_charset('utf8');
}
if ($lbOK) {
$id = NULL;
$user_name = NULL;
$user = htmlentities($user, ENT_QUOTES);
$lcSQL = "SELECT `user_name` FROM `users` WHERE user_name=?";
$stmt = $db -> prepare($lcSQL);
$ok = $stmt -> bind_param('s', $user);
$ok = $stmt -> execute();
$ok = $stmt -> bind_result($user_name);
while ($row = $stmt -> fetch()){
echo $user_name;
}
$stmt->close();
}
}
可能沒有人與where子句匹配! – rahularyansharma
您確定您擁有user_name'?'的用戶嗎? – Daanvn
是的,有些用戶符合條件。 –