我在将其从 mysql 转换为 mysqli 时遇到问题,我尝试了 php 文档所说的内容,但我仍然无法得到它。任何帮助,将不胜感激。
return (mysql_result(mysql_query("SELECT COUNT(id) FROM users WHERE (username = '$username' OR email = '$username') AND password = '$password'"), 0) == 1) ? $user_id : false;
我试过这个:
return (mysqli_data_seek(mysqli_query($con,"SELECT COUNT(id) FROM users WHERE (username = '$username' OR email = '$username') AND password = '$password'"), 0) == 1) ? $user_id : false;
整体功能:
function login($username, $password){
$con=mysqli_connect("127.0.0.1","root","","frostbase");
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = md5($password);
return (mysqli_data_seek(mysqli_query($con,"SELECT COUNT(id) FROM users WHERE (username = '$username' OR email = '$username') AND password = '$password'"), 0) == 1) ? $user_id : false;
mysqli_close($con);
}