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 );
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);
I have faced the same problem with my host, and for less code refactoring I think the better way is to implement a similar function using mysqli_fetch_assoc()
or mysqli_fetch_array()
, returning the same as mysqli_fetch_all()
,
like:
public function mysqli_fetch_all_alt($result) {
$select = array();
while( $row = mysqli_fetch_assoc($result) ) {
$select[] = $row;
}
return $select;
}
Then just perform a find-replace in your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With