Alternative to MySQLi_Fetch_All Needed

Alternative to mysqli_fetch_all needed

If mysqli_fetch_all is not available because your PHP installation was not compiled with mysqlnd, you have two options:

  1. Recompile PHP with mysqlnd or possibly install another specific package from your Linux distribution's package repository.

  2. Use a simple loop:

     $data = [];
    while ($row = $result->fetch_assoc()) {
    $data[] = $row;
    }

You could even create a compatibility fallback, without needing to change all your code:

if (!function_exists('mysqli_fetch_all')) {
function mysqli_fetch_all(mysqli_result $result) {
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
return $data;
}
}

mysqli_fetch_all not working on shared hosting, need alternative

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);

PHP: Unintentional multidimensional array insted of onedimenisonal

mysqli_fetch_row() returns an array of the columns in the SQL, so when you add it to the array...

$array[] = $row; 

This will create an array of each row - which is the array of arrays. If instead you add the column value to the array...

$array[] = $row[0];

This should give the result your after.

unbuffered query with MySQLi?

mysqli_real_query() followed by mysqli_use_result()



Related Topics



Leave a reply



Submit