从 mysql_result 更改为 mysqli_result
时,我收到此错误function f_exists($f_uname) {
$f_uname = sanitize($f_uname);
$conn = @mysqli_connect('localhost','root','','swift') or die($connect_error);
$query = mysqli_query($conn,"SELECT COUNT(`f_id`) FROM `flight_users` WHERE `f_uname`= '$f_uname'") or die(mysqli_error($conn));
//here is the problem
return (mysql_result($query, 0) == 1) ? true : false;
}
答案 0 :(得分:1)
请勿混用mysql_*
和mysqli_*
。此外,您无法在mysql_result
中使用mysql_*
。只需替换此
return (mysql_result($query, 0) == 1) ? true : false;
以下内容:
if ($query && mysqli_num_rows($query) == 1) {
$row = mysqli_fetch_assoc()['count_val'];
}
因此,您需要在语句中使用别名作为计数值,您应该始终这样做:SELECT COUNT(f_id) as count_val ...
有关mysql_result
中mysql_*
的等效内容的更多信息,请参阅此主题:MySQLi equivalent of mysql_result()?