Mysqli_fetch_all not working with a shared host needs an alternative

When developing on localhost through XAMPP, I used mysqli_fetch_all in my code. But after you send shared hosting to godaddy, it does not work.

I searched on the Internet and found that the server must use MySQLnd to run mysqli_fetch_all. Therefore, I cannot run my current code on the server.

I need an exact alternative to 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 ); 
+5
source share
2 answers

If you cannot use it because you do not have mysqlnd installed, select it as usual 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); 
+4
source

I ran into the same problem with my host, and to reduce code refactoring, I think the best way is to implement a similar function using mysqli_fetch_assoc() or mysqli_fetch_array() , returning the same thing 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 run the find-replace command in your project.

0
source

Source: https://habr.com/ru/post/1208714/


All Articles