致命错误:未捕获错误:调用未定义函数mysql_result()

时间:2016-11-07 15:12:27

标签: mysql

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; 

}

1 个答案:

答案 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_resultmysql_*的等效内容的更多信息,请参阅此主题:MySQLi equivalent of mysql_result()?