sumit sumit - 2 months ago 46
MySQL Question

mysqli_fetch_all not working on shared hostimg, need alternative

While developing on localhost via XAMPP I used mysqli_fetch_all in my code. But after uploading on godaddy shared hosting, its not working.

I researched on internet and found out server should use MySQLnd to run mysqli_fetch_all. So I can't run my current code on server.

I need exact alternative of this code. Any suggestions?

Current code:

$result = mysqli_query($con,$query);
$arr = mysqli_fetch_all($result, MYSQLI_ASSOC);

$totalrecords = count($arr);

$json = array('sEcho' => '1', 'iTotalRecords' => $totalrecords, 'iTotalDisplayRecords' => $totalrecords, 'aaData' => $arr);
echo json_encode($json );

Answer

If you can't use it because you don't have mysqlnd installed, then fetch it like the you would normally do with mysqli_fetch_assoc()

$arr = array();
$result = mysqli_query($con,$query);
$totalrecords = mysqli_num_rows($result);
while($row = mysqli_fetch_assoc($result)) {
    $arr[] = $row;
}

$json = array('sEcho' => '1', 'iTotalRecords' => $totalrecords, 'iTotalDisplayRecords' => $totalrecords, 'aaData' => $arr);
echo json_encode($json);