My code for this error Fatal error: Call to a Member Function fetch_assoc() on Boolean

Asked

Viewed 865 times

0

Does anyone know why this mistake in php when viewing a table on mysql

"Fatal error: Call to a Member Function fetch_assoc() on Boolean in /Storage/Emulated/0/site/store/Adm/editar_produto.php on line 85"

Since on another page using the same code works normal, the code is below. On the same page I look for information to be edited.

$sql ="Select * from categorias";
$resultado = $con ->real_query($sql);
$resultado= $con->use_result();
while($row = $resultado->fetch_assoc()){
   echo $row["id"] ."$nbsp;";
   echo $row['nome'] ."<br>"; 
}

1 answer

1


It’s simple, $resultado= $con->use_result(); returned FALSE, soon if $resultado has FALSE as value is not object and it is impossible to access ->fetch_assoc()

Then it would be enough to deal with a IF and use $con->error to get the query error, which is what is causing the return FALSE of use_result

Example:

$resultado = $con->use_result();

if ($resultado) {
    while($row = $resultado->fetch_assoc()){
       echo $row["id"] ."$nbsp;";
       echo $row['nome'] ."<br>"; 
    }
} else {
    die($con->error);
}

Browser other questions tagged

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