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:
Recompile PHP with mysqlnd or possibly install another specific package from your Linux distribution's package repository.
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
Simplexmlelement and Xpath, Getting Empty Array()
How to Set Base Url for All Pages of My Website
Use of Undefined Constant Stdin - Assumed 'Stdin' in C:\Wamp\Www\Study\Sayhello.PHP on Line 5
Replace the Last Comma with an & Sign
Easiest Way to Implode() a Two-Dimensional Array
Google Map: Is a Lat/Lng Within a Polygon
Hightest Value of an Associative Array
Seems Like Post Values Are Lost When .Htaccess Rewriterule Used. Get Values Are Ok. How to Fix
How to Convert a Single Array into a Multidimensional Array in PHP
Getting Elements of a Div from Another Page (Php)
How to Make a Select in PHP/MySQL Case Insensitive
Connect to Azure Active Directory from PHP Web Application
Passing and Parse Paypal Ipn Custom Field
Including PHP Variables in an External Js File
Can Not Increase File Upload Size Wamp
Jquery $.Post Processing JSON Response
How to Backup/Export the Connected Database Database.SQL File in Laravel