Uncaught Error: Call to a Member Function fetch() on Boolean

Asked

Viewed 1,407 times

1

I have a problem in a project.

I can not solve, was running the same code until yesterday. Simply today, no longer works.

I will send here the function that is a select in the database.

Thank you.

function selecionar() {

    $query = "SELECT eve_id, usr_id, eve_nascimento, eve_instituicao, eve_categoria, "
            . "eve_sexo, eve_rondonista, eve_cep, eve_uf, eve_cidade, eve_bairro, "
            . "eve_logradouro, eve_numero, eve_complemento, eve_jantar, eve_fovoco, "
            . "eve_running, eve_encerramento, eve_preco, eve_status FROM evento ORDER BY eve_id";

    $resultado = $this->conexao->query($query);

    $eventos = array();

    for ($i = 0; $registro = $resultado->fetch(PDO::FETCH_NUM); $i++) {

        $eventos[$i] = new Evento();

        $eventos[$i]->set_eve_id($registro[0]);
        $eventos[$i]->set_usr_id($registro[1]);
        $eventos[$i]->set_data_nascimento($registro[2]);
        $eventos[$i]->set_instituicao($registro[3]);
        $eventos[$i]->set_categoria($registro[4]);
        $eventos[$i]->set_sexo($registro[5]);
        $eventos[$i]->set_rondonista($registro[6]);
        $eventos[$i]->set_cep($registro[7]);
        $eventos[$i]->set_uf($registro[8]);
        $eventos[$i]->set_cidade($registro[9]);
        $eventos[$i]->set_bairro($registro[10]);
        $eventos[$i]->set_logradouro($registro[11]);
        $eventos[$i]->set_numero($registro[12]);
        $eventos[$i]->set_complemento($registro[13]);
        $eventos[$i]->set_jantar($registro[14]);
        $eventos[$i]->set_fovoco($registro[15]);
        $eventos[$i]->set_running($registro[16]);
        $eventos[$i]->set_encerramento($registro[17]);
        $eventos[$i]->set_preco($registro[18]);
        $eventos[$i]->set_eve_status($registro[19]);
    }

    return $eventos;
}`

Edit. Error in full:

Fatal error: Uncaught Error: Call to a member function fetch() on boolean in /var/www/html/web_rondon/database/UsuarioDAO.php:64 Stack trace: #0 /var/www/html/web_rondon/helpers/validacao.php(165): UsuarioDAO->selecionar() #1 /var/www/html/web_rondon/inscricao.php(32): consultar_cpf('075.597.455-71') #2 {main} thrown in /var/www/html/web_rondon/database/UsuarioDAO.php on line

  • If $resultado is a boolean is because it is fake and its SQL is wrong. Review it and test it directly in your test database.

  • I think I missed the query, $resultado->execute(); before the for()

No answers

Browser other questions tagged

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