My code was working correctly on localhost, but when I upload 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 this 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>