ModelsUpdate.php
1.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
class ModelsUpdate extends ModelsConn {
private $tabela;
private $dados;
private $termos;
private $values;
private $result;
private $msg;
private $query;
private $conn;
public function exeUpdate($tabela, array $dados, $termos, $parseString) {
$this->tabela = (string) $tabela;
$this->dados = $dados;
$this->termos = (string) $termos;
parse_str($parseString, $this->values);
$this->getIntrucao();
$this->executarInstrucao();
}
public function getResult() {
return $this->result;
}
public function getMsg() {
return $this->msg;
}
public function getRowCount() {
return $this->query->rowCount;
}
public function conexao() {
$this->conn = parent::getConn();
$this->query = $this->conn->prepare($this->query);
}
private function getIntrucao() {
foreach ($this->dados as $key => $value) {
$values[] = $key . ' = :' . $key;
}
$values = implode(', ', $values);
$this->query = "UPDATE {$this->tabela} SET {$values} {$this->termos}";
}
private function executarInstrucao(){
$this->conexao();
try {
$this->query->execute(array_merge($this->dados, $this->values));
$this->result = true;
$this->msg = "<div class=\"alert alert-danger\" role=\"alert\">
Usuário alterado com sucesso!
</div>";
} catch (Exception $e) {
$this->result = null;
$this->msg = "<div class=\"alert alert-success\" role=\"alert\">
Erro ao Alterar</b> {$e->getMessage()}
</div>";
}
}
}