ModelsCreate.php
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class ModelsCreate extends ModelsConn {
private $tabela;
private $dados;
private $query;
private $conn;
private $msg;
private $result;
public function ExeCreate($tabela, array $dados){
$this->tabela = (string) $tabela;
$this->dados = $dados;
$this->getInstrucao();
$this->executarInstrucao();
}
public function getInstrucao(){
$keys = implode(', ', array_keys($this->dados));
$values = ':' . implode(', :', array_keys($this->dados));
$this->query = "INSERT INTO {$this->tabela} ({$keys}) VALUES ({$values})";
}
private function executarInstrucao() {
$this->conexao();
try {
$this->query->execute($this->dados);
$this->result = $this->conn->lastInsertId();
}catch (Exception $e) {
$this->result = null;
return "<strong>Erro ao Cadastrar: </strong> {$e->getMessage()}";
}
}
public function conexao(){
$this->conn = parent::getConn();
$this->query = $this->conn->prepare($this->query);
}
public function getMsg(){
return $this->msg;
}
public function getResult(){
return $this->result;
}
}