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!– rray
the code is incomplete, so it becomes more difficult to analyze the problem, put the important parts, the class Client.
– Edilson
in the method list before the fetchAll puts a stmt->execute, and see what happens.
– Edilson
Dilson gave property n defined, this caca is already giving me a huge headache!
– Golpian
@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
– Edilson
Post var_dump content($client->list())
– Rodrigo Jarouche