1
So, I’m doing the maintenance of a very large system. I have the query:
$query = $mysqli->query("SELECT*FROM tabela");
And the problem is they used fetch_all()
to return the data. When the query does not return records the method fetch_all()
is not defined in the class mysqli_result
. Therefore when the query does not return records and I try to call it, I have the Warning undefined method.
I used to do something like:
$resultado = $query->num_rows > 0 ? $query->fetch_all() : array();
this makes it $resultado
turn a blank array if the query has no records returned. The problem is that many lines of code must be edited. Is there any way to "create" this method fetch_all()
on the object and make it return a blank array if the query does not return records? (same or any other alternative).
@Edit
I found out that the mysqlnd
. But the question follows: how to do the fetch_all()
be called even if it does not exist?
Grateful
The
fetch_all()
will not work if the query has any error, if there is nothing it works normal but does not return records.– rray
Thank you. I looked for why I am making a mistake and it is because mysqlnd is missing from the server. I will edit the question.
– Wallace Magalhães
Change the
fetch_all()
forfetch_array()
is very complicated?– rray
In this situation yes, because thousands of lines should be changed. :/
– Wallace Magalhães
What do you mean? has many calls from
fetch_all()
?– rray
Exactly that.
– Wallace Magalhães
And ask for hosting to install mysqlnd is possible?
– rray