fetch_array() error in php7

Asked

Viewed 206 times

1

I used this code in php version 5, but after I switched to php 7, this error appeared.

Fatal error: Uncaught Error: Call to a Member Function fetch_array() array on

$selec = $mysqli->query("SELECT cpf_cnpj, isento, ... ");
$exec = $selec->fetch_assoc();

while($campos = $exec->fetch_array()) {
    extract($campos);
    $Array = Array(); 

    $Array[] = Array(
                        "cpf_cnpj"  => "$cpf_cnpj",
                        "isento"    => "$isento", 
                    ); 

    $json_encode = json_encode($Array); 
    echo $json_encode; 
}

What am I doing wrong?

Thank you.

  • 1

    very provavle some error in your query put this code after the query and see if Tis any error or $mysqli->query("SELECT cpf_cnpj, exempt, ... ") die(mysqli_error($db))

  • @Marcosbrinnerpikatoons appeared this error Parse error: syntax error, Unexpected 'die' (T_EXIT)

  • an ai "or" was missing before die $mysqli->query("SELECT cpf_cnpj, exempt, ... ") or die(mysqli_error($db))

  • 1

    @Marcosbrinnerpikatoons No error in Query, returned with the same error Fatal error: Uncaught Error: Call to a Member Function fetch_array() on array

1 answer

0

Change your code you are doing the fetch() sometimes put the MYSQLI_ASSOC inside your Fetch_array()

<?php
$selec = $mysqli->query("SELECT cpf_cnpj, isento, ... ");


while($campos = $selec->fetch_array(MYSQLI_ASSOC)) {



    $json_encode = json_encode($campos); 
    echo $json_encode; 
}
?>
  • No error appears, but also no result appears, gets blank screen.

  • I made a change to the code inside while try now

Browser other questions tagged

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