how to get database names with object-oriented php

0

Good morning I have a question as to how to get all the data registered in the database with my code. because I'm trying and my while is entering loop infinite could anyone help me?

class code:

require_once 'banco.php';
    class Album{
        public $id;
        public $nomeAlbum;
        public $img;



        public function listAll(){
            $con = new Conexao();
            $con->conectar();

            $sql = mysqli_query($con->conectar(), "SELECT nome_album, img FROM album");
            $con->desconectar();

            return $sql;
        }
    }

index code

require_once "album.class.php";
    $obj = new Album();

while($aux = mysqli_fetch_object($obj->listAll())){
  echo $aux->img;
}
    
asked by anonymous 07.11.2017 / 10:44

1 answer

0

You are entering an infinite loop because you are looping 'enquanto' into a query object, you need to fetch to a variable, and then open loop in it:

require_once "album.class.php";
$obj = new Album();
$aux = mysqli_fetch_array($obj->listAll())
foreach($aux as $row){
  echo $row['img'];
}
    
07.11.2017 / 11:32