خرید بک لینک

Vote count: 0

I'm getting this fatal error when trying to execute a insert query.

Here in DaoUsuario.php line 27 -> $banco->query($queryInsert);

My code:

Index.php

<?php

  if($_POST['botao']){
    $nome = $_POST['nome'];
    $sobrenome = $_POST['sobrenome'];
    $cpf = $_POST['cpf'];
    $usuario = $_POST['usuario'];
    $senha = $_POST['senha'];

    $u = new Usuario;
    $u->setNome($nome);
    $u->setSobrenome($sobrenome);
    $u->setCpf($cpf);
    $u->setUsuario($usuario);
    $u->setSenha($senha);

    $daoUsuario = new DaoUsuario;
    $daoUsuario->insertUsuario($u);
  }
?>

DaoUsuario.php

<?php

  include_once './models/Usuario.php';
  include_once 'coectionFactory.php';

  class DaoUsuario {

    private $dbh;

    function DaoUsuario(){
      $this->dbh = new CoectionFactory;
    }

    function insertUsuario(Usuario $u) {
      mysqli_report(MYSQLI_REPORT_STRICT);

      $nome = $u->getNome();
      $sobrenome = $u->getSobrenome();
      $cpf = $u->getCpf();
      $usuario = $u->getUsuario();
      $senha = $u->getSenha();

      $queryInsert = "insert into usuario (nome, sobrenome, cpf, usuario, senha) values (
        $nome, $sobrenome, $cpf, $usuario, $senha)";
      echo $queryInsert;
      $banco = $this->dbh->getDbh();
      $banco->query($queryInsert);
      $this->dbh->fechaConexao();
      echo "Inserido com sucesso!";
    }
  }
?>

coectionFactory.php

class CoectionFactory {
#atributos..
private $servidor = 'localhost';
private $usuario = 'root';
private $senha = 'admin';
private $bd = 'sistemaloja';
private $dbh;

#métodos..
public function abreConexao(){
  mysqli_report(MYSQLI_REPORT_STRICT);
  error_reporting(!E_NOTICE);

  try{
    $this->dbh = new mysqli_coect($this->servidor, $this->usuario, $this->senha, $this->bd);
  }catch (Exception $e){
    echo ("Erro ao conectar!");
    echo ("Mensagem: " . $e->getMessage());
    exit;
  }
}

public function fechaConexao(){
  $this->dbh->close();
}

Any idea on how to fix this? Also, I know that I'm not using all the Object-Oriented concepts since I'am leaing.

asked 2 mins ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 21 تير 1395 ساعت: 5:39

صفحه بندی