0

I'm trying make a query in SQL in order to get some data, but my fetchAll() isn't working. I'm trying to return the result of the query in the end of the function, but i got the error : Fatal error: Uncaught Error: Call to a member function fetchAll() on boolean. My connection with database works fine in every test, so i know that file may be okay, it seems it's some problem in the query function that i's in other file.

Here's my file funcoes_db.php:

require_once("conecta_db.php");

$db = new Db();
$con = $db->conexao;

/* Class Declaration */

class FuncoesDb{

function listaSlides(){
    global $con;
    $where = "";
    $sql = "SELECT imgsld.img_nome, imgsld.legenda FROM slid_imgs imgsld";

    $obj = $con->prepare($sql." ".$where);
    $imagens = $obj->execute();

    $imgs = $imagens->fetchAll(PDO::FETCH_ASSOC);
    return $imgs;
}

And how i'm trying to get the returned value in my index.php:

require_once("funcoes/funcoes_db.php");

$func = new FuncoesDb();
$imgs = $func->listaSlides();
Vigikaran
  • 725
  • 1
  • 10
  • 27
Gabriel Ozzy
  • 73
  • 1
  • 7
  • replace `FROM slid_imgs imgsld ` with `FROM slid_imgs, imgsld ` or with `FROM imgsld ` – fusion3k Mar 14 '16 at 23:01
  • 1
    Actually this wasn't a duplicate, i'll post my answer here in the comments... The problem was here: `$imagens = $obj->execute();`, i should do just and `$obj->execute();` and then, make my var $imagens do the fetch like `$imagens = $obj->fetchAll(PDO::FETCH_ASSOC);`. Thanks for the attention anyway ! – Gabriel Ozzy Mar 16 '16 at 23:29

0 Answers0