I see comparisons between mysqli_fetch_array()
and mysqli_fetch_all()
that say that with mysqli_fetch_all()
it will take more memory a
It has nothing to do with whatever efficiency. It's all about usability only.
fetch_all()
is a thing that is called a "syntax sugar" - a shorthand to automate a frequently performed operation. It can be easily implemented as a userland function:
function mysqli_fetch_all ($resouce, $mode = MYSQLI_BOTH)
{
$ret = [];
while ($row = $resource->fetch_array($mode))
{
$ret[] = $row;
}
return $ret;
}
Thus you can tell use cases for these functions:
fetch_all()
have to be used if you need an array, consists of all the returned rows, that will be used elsewhere.fetch_assoc()
in a loop have to be used if you're going to process all the rows one by one right in place.As simple as that.
These functions bear different purpose and thus there is no point in comparing them.
Note that PDO is tenfold more sweet in terms of syntax sugar, as it's fetchAll()
function can return data in dozens different formats