在linux服务器上的非对象上调用成员函数fetch_assoc(),但不在Windows上调用

I am getting the above error when I run this page on a linux server, but it doesn't give me any errors when running it on a windows machine. The following is my script:

include_once '/../src/init.php';
$userid = $user_data['userid'];

$date = ('Y-m-d'); //get todays date from the server


$db = new mysqli('localhost', 'root', '', 'logfile');

if ($db->connect_error) {


   $error = $db->connect_error;

} else {

$sql = "SELECT a.kiloLogid,a.travelDate,a.openning, a.closing, a.clientsName,a.timeIn,a.timeOut, a.destination,a.diff
                FROM viewDailyDiff a
                WHERE a.`userid` = $userid AND a.`travelDate` = '".$date."'";
$result = $db->query($sql);
if ($db->error) {
    $error = $db->error;
}
}






function getRow($result)

{

 return $result->fetch_assoc();  //the error is on this line

}

Please assist

I thing the included file init.php should have the call for the getRow function.

and when there is a problem with Linux to Windows change there are most chances to find solution with .htaccess. Try not to download the .htaccess

All the best

Usually when this happens to me, it's because there is no data returned. If the "work/fail" change is moving to a new server, often this is because the new server has no permission to get the data. So no results are returned. Even thought the original server with the same select statement had records returned, avoiding the error.

If no results are returned, calling fetch_assoc on an empty data set will toss an error in more recent php. So the version of php from one server to the next can also be a factor.

Put in code to only call fetch_assoc if there are records returned (never a bad idea) and/or try to run the command manually (command line?) using mysql client from the command prompt to verify permissions and data. Often the ClI will be more verbose with the error results.