does not return mysql client names

Asked

Viewed 32 times

0

CLASS

class Cliente
{
    private $db;

    private $id;
    private $nome;
    private $email;


    public function __construct(PDO $db)
    {
        $this->db=$db;
    }

    public function listar()
    {
        $query = "select * from pessoas";

        $stmt = $this->db->prepare($query);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }

OBJECT

try
{
 $conexao = new PDO("mysql:host=localhost;dbname=estudos","root","xxxxxxxxx");

}catch(PDOExeption $e)
{
    die("Não foi possive l estabelecer a conexão com o banco de dados. ERRO=" . $e->getCode());
}

$cliente = new Cliente($conexao);

foreach($cliente->listar() as $i)

{
    $i['nome'] . "<br>";
}
  • Place these lines at the beginning of the file and see if the error appears. ini_set('display_errors', true); error_reporting(E_ALL);. Focus on the problem!

  • the code is incomplete, so it becomes more difficult to analyze the problem, put the important parts, the class Client.

  • in the method list before the fetchAll puts a stmt->execute, and see what happens.

  • Dilson gave property n defined, this caca is already giving me a huge headache!

  • @Golpian look this may be for several reasons, maybe the very PDO object $db you’re using, try it with this section in the Pastebin

  • Post var_dump content($client->list())

Show 1 more comment
No answers

Browser other questions tagged

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