1
I’m trying to unite three tables in my database, being them Propriedades | Licitacoes | Usuarios
. Only every time of the same mistake! he is:
Fatal error: Call to a member function fetchAll() on a non-object in *** on line 61
The goal to which I am trying to join this table is to filter the information at the time of the echo
, so much so that I’m using the WHERE
at the end of the code. I want that the moment the user enters the page in question show only the results related to it, this relation is given by licitacoes
that the user has and Nivel
that he owns.
I’ve used almost the same code on another occasion and there was no similar mistake. I don’t know why it’s giving! Can you help me??
<?php
require_once "../conexao.php";
?>
<?php
$rs = $pdo->query(" SELECT a.ID as IDPROP, a.LICITI, a.NOME, a.NIVEL as NIPROP,
b.ID as IDLICI, b.ID_LICITI, b.ID_USER,
c.ID as IDCHAR, c.USUARIO, c.NIVEL as c.NICHAR
FROM propriedades a INNER JOIN licitacoes b on (a.LICITI = b.ID_LICITI)
INNER JOIN usuario c on (b.ID_USER = c.ID)
")->fetchAll();
if(!$rs){ print_r($pdo->errorInfo()); }foreach ($rs as $row){
?>
<?php echo $row['IDPROP'];?> = Informações da tabela propriedades
<?php echo $row['IDLICI'];?> = Informações da tabela licitacoes
<?php echo $row['IDCHAR'];?> = Informações da tabela usuario
<?php } ?>
Is missing the
ON
in theINNER JOIN
, No? It appears that error?– Lucas
Print the query and run directly to the database see if any errors appear.
– rray
@Lucas was really missing the ON, but this did not solve! The error I listed in the question! " Fatal error: Call to a Member Function fetchAll() on a non-object in *** on line 61"
– ivan veloso
@rray run directly on the seat? What do you mean?
– ivan veloso
This is because
query()
failed is usually an error in the query, so you cannot string thefetchAll()
. When the query fails is returned the sql state that says the error message, 'category' and code.– rray
What the SQL error I meant, sorry
– Lucas
It would play the query in a variable and print it, then test in the Workbench or phpmyadmin,
$sql = 'select ....'; echo $sql; $pdo->query($sql); ...
– rray
I think it’s some bad closure! Because the page never finishes loading, it’s like it’s in infinite loop
– ivan veloso
The
Fatal error
, after you put theON
?– Lucas
@Lucas ta yes. The error is the same!
– ivan veloso
I saw another mistake there:
c.NIVEL as c.NICHAR
, removes the latter alias, be alonec.NIVEL as NICHAR
– Lucas
@Lucas OBRIGADO. This last mistake that you talk about solved the problem!
– ivan veloso
Show. I will add an answer.
– Lucas