Call to a Member Function prepare() on a non-object in /var/www/studies/studyCRUD/classes/client.php l on line 24

Asked

Viewed 48 times

0

object

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

}catch(PDOExeption $e)
{
    die  ("não foi possovem conectar " . $e->getCode() . ": " . $e->getMessage());
}

$cliente = new Cliente($conexao);

$cliente->setNome("fulano")
        ->setEmail("[email protected]"); 

$resultado = $cliente->inserir();

class

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


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

    public function listar()
    {}

    public function inserir()
    {

        $query = "Insert into pessoas(nome, email) values(:nome, :email)";

        $stmt = $this->db->prepare($query);
        $stmt->bindValue(':nome', $this->getNome());
        $stmt->bindValue(':email', $this->getEmail());

        $stmt->execute();

    }

    public function alterar()
    {}

    public function deletar()
    {}

    public function setNome($nome)
    {
        $this->nome = $nome;
        return $this;
    }
    public function getNome()
    {
        return $this->nome;
    }

    public function setEmail($email)
    {
        $this->email = $email;
        return $this;
    }
    public function getEmail()
    {
        return $this->email;
    }


    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }
    public function getId()
    {
        return $this->id;
    }








}

  • What mistake? Golpian

  • Call to a Member Function prepare() on a non-object in /var/www/studies/studyCRUD/classes/client.php l on line 24 - however I analyze and do not see the error :-( !

No answers

Browser other questions tagged

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