Fatal error: Call to a Member Function result() on a non-object

Asked

Viewed 1,025 times

0

Hello. After hours trying to solve this problem and researches I did about the problem, I came to ask you how I can remedy this question

The mistake is:

Fatal error: Call to a Member Function result() on a non-object in /home/iaulas/public_html/system/application/models/site_model.php on line 483

I removed the line referring to the error to see if this error occurred in some other location and in another line the same error occurs.

This is the function: (I use the codeigniter framework)

        function cat_busca() { 
        $query = 'SELECT materiais_cat_id as id, MCCat as cat, MCOrdem as ordem FROM ((SELECT * FROM materiais_cat where materiais_cat.MCMostrar = "Sim" GROUP BY MCCat) UNION (SELECT * FROM livros_cat WHERE livros_cat.LCMostrar = "Sim" GROUP BY LCCat) UNION (SELECT * FROM cursos_cat WHERE cursos_cat.CCMostrar = "Sim" GROUP BY CCCat)) AS tabela ORDER BY ordem';
        $retorno = $this->db->query($query);
        return $retorno->result();
    }

I couldn’t post all the code because it’s almost 4,000 lines.

In addition to help to fix, I would like to understand why this error occurs as it happened only after I changed the hosting site.

Thank you very much!

1 answer

1


This error is caused by your command line SQL that is in the variable $query. I have been through this problem several times until I get back to me if there was a line at least of this query.

For you not to pass this kind of problem it is advisable that you always check the number of rows returned, thus leaving your code:

function cat_busca() { 
        $query = 'SELECT materiais_cat_id as id, MCCat as cat, MCOrdem as ordem FROM ((SELECT * FROM materiais_cat where materiais_cat.MCMostrar = "Sim" GROUP BY MCCat) UNION (SELECT * FROM livros_cat WHERE livros_cat.LCMostrar = "Sim" GROUP BY LCCat) UNION (SELECT * FROM cursos_cat WHERE cursos_cat.CCMostrar = "Sim" GROUP BY CCCat)) AS tabela ORDER BY ordem';
        $retorno = $this->db->query($query);
if($retorno->num_rows() > 0){
        return $retorno->result();
}else{
return false;
}
}

The mistake

Fatal error: Call to a Member Function result() on a non-object in /home/iaulas/public_html/system/application/models/site_model.php on line 483

means the function you call result() is not an object, that is, has no record and you are forcing it to print an object that has no.

Always check the number of lines to see if you have returned any. If you think this error is strange and you would have to return something, then check your command SQL of $query, maybe the mistake is there.

Browser other questions tagged

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