Error "Call to undefined function mysqli fetch all"
Swears at mysqli_fetch_all
when posted on the 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;
}
2
2 answers
The documentation says the following:
Only for MySQL Native Driver
Available only with the mysqlnd extension.
I am not sure that you want to immediately fill up your memory by returning all the rows to the array, especially when it is logical to imagine that your memory is limited and the selection from the database is N-the number of rows. Here, a logical solution immediately matures to call the fetch_assoc() function many times in a loop, so that each subsequent 'tick' overwrites the variable only one line.
while($row = $res->fetch_assoc()){ }
Brilliant, isn't it?)
2
Author: programmer403, 2020-06-12 12:52:24
Use fetch_assoc
in a loop, or make queries using PDO.
0
Author: Dmitry Maslennikov, 2017-07-06 13:15:04