Swears on mysqli_fetch_all when laid out on a hosting.

Fatal error: Call to undefined function mysqli_fetch_all () in /home/admin/models/options_model.php on line 6

  function get_options(){ global $connection; $query = "SELECT * FROM options"; $res = mysqli_query($connection, $query); if($res){ return mysqli_fetch_all($res, MYSQLI_ASSOC); } return false; } 
  • one
    No mysqli module for php hosting? - nobody
  • one
    do so while($row = $res->fetch_assoc()){ } - Raz Galstyan

2 answers 2

The documentation states the following:

Only for MySQL Native Driver

Only available with the mysqlnd extension.

I'm not sure that you want to immediately fill in the memory by returning all the rows to the array, especially when it is logical to imagine that you have limited memory and the sample from the base is N-number of rows. Here a logical decision is immediately brewing to call the function fetch_assoc () many times in a loop, so that each subsequent 'tick' overwrites the variable with just one line.

 while($row = $res->fetch_assoc()){ } 

Brilliant is not it?)

  • This answer can be considered correct. And exit 2: either convince the host to install mysqlnd, or read line by line. - PA
  • @PA you are absolutely right! - programmer403

Use fetch_assoc in a loop, or make queries using PDO.

  • If there was no mysqli module, then the error would have spilled on the line $ res = mysqli_query ($ connection, $ query); or, more precisely, mysqli_connect. As it’s rightly noted below, it’s in the mysql driver. - PA
  • @PA corrected the answer - Dmitry Maslennikov