Fatal error: Call to Undefined method mysqli_result::fetch_all()

Asked

Viewed 1,227 times

1

My code was working correctly on the localhost, but when I went up to my web page, the following error appeared:

Fatal error: Call to Undefined method mysqli_result::fetch_all() in

This is the source code:

function find($table = null, $id = null) {
$database = open_database();
$found = null;
if ($id) {
    $sql = "SELECT * FROM " . $table . " WHERE Codigo = " . $id;
    $result = $database->query($sql);

    if ($result->num_rows > 0) {
        $found = $result->fetch_assoc();
    }
} else {
    $sql = "SELECT * FROM " . $table . " WHERE Status = true";
    $result = $database->query($sql);

    if ($result->num_rows > 0) {
        $found = $result->fetch_all(MYSQLI_ASSOC);
    }
}

close_database($database);
return $found;
}

The error is in that line: $found = $result->fetch_all(MYSQLI_ASSOC);

This is the foreach that lists the data, maybe it helps to find the error:

<?php if ($funcionarios) : ?>
<?php foreach ($funcionarios as $funcionario) : ?>
<tr>
    <td><?php echo $funcionario['NomeCompleto']; ?></td>
    <td><?php echo $funcionario['Porcentagem']; ?></td>
    <td class="actions text-right">
    <a href="Detalhes.php?Codigo=<?php echo $funcionario['Codigo']; ?>" class="btn btn-sm btn-success"><i class="glyphicon glyphicon-eye-open"></i> Visualizar</a>
        <a href="Editar.php?Codigo=<?php echo $funcionario['Codigo']; ?>" class="btn btn-sm btn-warning"><i class="glyphicon glyphicon-pencil"></i> Editar</a>
        <a href="Excluir.php?Codigo=<?php echo $funcionario['Codigo']; ?>" class="btn btn-sm btn-danger"><i class="glyphicon glyphicon-trash"></i> Excluir</a>
    </td>
</tr>
  • sees if the extension msqli is enabled in PHP where you hosted the site.

  • 1

    This function needs mysql client installed if you don’t have to change the fetch_all() for fetch() and a while.

  • @rray, you can help me mount the while?

1 answer

1


mysql_fetch_all() needs the Mysql Native driver installed, if you don’t have it, exchange it for a fetch() matching while.

$sql = "SELECT * FROM " . $table . " WHERE Status = true";
$result = $database->query($sql);
$registros = array();
while($row = $result->fetch_assoc()){
   $registros[] = $row;
}

return $registros;
  • Thank you so much again for always helping me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.