├── PHP - Aula MVC.pptx
├── Banco de Dados
├── Modelagem.mwb
└── Modelagem.mwb.bak
├── View
├── udy.php
└── modules
│ ├── Produto
│ ├── ProdutoCadastro.php
│ └── ProdutoListar.php
│ ├── CategoriaProduto
│ ├── CategoriaProdutoCadastro.php
│ └── CategoriaProdutoListar.php
│ ├── Pessoa
│ ├── ListaPessoas.php
│ └── FormPessoa.php
│ └── Funcionario
│ ├── ListaFuncionario.php
│ └── FormFuncionario.php
├── Model
├── ProdutoModel.php
├── CategoriaProdutoModel.php
├── PessoaModel.php
└── FuncionarioModel.php
├── Controller
├── ProdutoController.php
├── CategoriaProdutoController.php
├── FuncionarioController.php
└── PessoaController.php
├── DAO
├── CategoriaProdutoDAO.php
├── ProdutoDAO.php
├── FuncionarioDAO.php
└── PessoaDAO.php
└── index.php
/PHP - Aula MVC.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thiag0-dot/php_mvc/HEAD/PHP - Aula MVC.pptx
--------------------------------------------------------------------------------
/Banco de Dados/Modelagem.mwb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thiag0-dot/php_mvc/HEAD/Banco de Dados/Modelagem.mwb
--------------------------------------------------------------------------------
/Banco de Dados/Modelagem.mwb.bak:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thiag0-dot/php_mvc/HEAD/Banco de Dados/Modelagem.mwb.bak
--------------------------------------------------------------------------------
/View/udy.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/View/modules/Produto/ProdutoCadastro.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Cadastro de produto
8 |
11 |
12 |
13 |
27 |
28 |
--------------------------------------------------------------------------------
/View/modules/CategoriaProduto/CategoriaProdutoCadastro.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Cadastro de categoria de produto
8 |
11 |
12 |
13 |
25 |
26 |
--------------------------------------------------------------------------------
/Model/ProdutoModel.php:
--------------------------------------------------------------------------------
1 | id))
15 | {
16 | $dao->insert($this);
17 |
18 | } else
19 | {
20 | $dao->update($this);
21 | }
22 | }
23 |
24 | public function getAllRows()
25 | {
26 | include 'DAO/ProdutoDAO.php';
27 |
28 | $dao = new ProdutoDAO();
29 |
30 | $this->rows = $dao->select();
31 | }
32 |
33 | public function getById(int $id)
34 | {
35 | include 'DAO/ProdutoDAO.php';
36 |
37 | $dao = new ProdutoDAO();
38 |
39 | $obj = $dao->selectById($id);
40 |
41 | return ($obj) ? $obj : new ProdutoModel();
42 | }
43 |
44 | public function delete(int $id)
45 | {
46 | include 'DAO/ProdutoDAO.php';
47 |
48 | $dao = new ProdutoDAO();
49 |
50 | $dao->delete($id);
51 | }
52 | }
--------------------------------------------------------------------------------
/Model/CategoriaProdutoModel.php:
--------------------------------------------------------------------------------
1 | id))
14 | {
15 | $dao->insert($this);
16 |
17 | } else
18 | {
19 | $dao->update($this);
20 | }
21 | }
22 |
23 | public function getAllRows()
24 | {
25 | include 'DAO/CategoriaProdutoDAO.php';
26 |
27 | $dao = new CategoriaProdutoDAO();
28 |
29 | $this->rows = $dao->select();
30 | }
31 |
32 | public function getById(int $id)
33 | {
34 | include 'DAO/CategoriaProdutoDAO.php';
35 |
36 | $dao = new CategoriaProdutoDAO();
37 |
38 | $obj = $dao->selectById($id);
39 |
40 | return ($obj) ? $obj : new CategoriaProdutoModel();
41 | }
42 |
43 | public function delete(int $id)
44 | {
45 | include 'DAO/CategoriaProdutoDAO.php';
46 |
47 | $dao = new CategoriaProdutoDAO();
48 |
49 | $dao->delete($id);
50 | }
51 | }
--------------------------------------------------------------------------------
/View/modules/CategoriaProduto/CategoriaProdutoListar.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Lista de categoria de produto
8 |
13 |
14 |
15 |
16 |
17 |
18 | | Delete |
19 | Id |
20 | Descrição |
21 |
22 |
23 | rows as $item): ?>
24 |
25 | |
26 |
27 | X
28 |
29 | |
30 |
31 | = $item->id ?> |
32 |
33 |
34 | = $item->descricao ?>
35 | |
36 |
37 |
38 |
39 |
40 |
41 |
42 | rows) == 0): ?>
43 |
44 | | Nenhum registro encontrado. |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/Controller/ProdutoController.php:
--------------------------------------------------------------------------------
1 | getAllRows();
13 |
14 | include 'View/modules/Produto/ProdutoListar.php';
15 | }
16 |
17 | //rota form
18 | public static function form()
19 | {
20 | include 'Model/ProdutoModel.php';
21 | $model = new ProdutoModel();
22 |
23 | if(isset($_GET['id']))
24 | $model = $model->getById( (int) $_GET['id']);
25 | include 'View/modules/Produto/ProdutoCadastro.php';
26 | }
27 |
28 | //rota save
29 |
30 | public static function save()
31 | {
32 | include 'Model/ProdutoModel.php';
33 |
34 | $produto = new ProdutoModel;
35 | $produto->id = $_POST['id'];
36 | $produto->nome = $_POST['nome'];
37 | $produto->preco = $_POST['preco'];
38 |
39 | $produto->save();
40 | header("Location: /produto");
41 | }
42 |
43 | //rota deletar
44 | public static function delete()
45 | {
46 | include 'Model/ProdutoModel.php';
47 |
48 | $delete = new ProdutoModel();
49 |
50 | $delete->delete( (int) $_GET['id'] );
51 |
52 | header("Location: /produto");
53 | }
54 | }
--------------------------------------------------------------------------------
/Model/PessoaModel.php:
--------------------------------------------------------------------------------
1 | id))
16 | {
17 | $dao->insert($this);
18 |
19 | } else
20 | {
21 | $dao->update($this);
22 | }
23 | }
24 |
25 | /**
26 | * Método que encapsula a chamada a DAO e que abastecerá a propriedade rows;
27 | * Esse método é importante pois como a model é "vista" na View a propriedade
28 | * $rows será acessada e possibilitará listar os registros vindos do banco de dados
29 | */
30 | public function getAllRows()
31 | {
32 | include 'DAO/PessoaDAO.php';
33 |
34 | $dao = new PessoaDAO();
35 |
36 | $this->rows = $dao->select();
37 | }
38 |
39 | public function getById(int $id)
40 | {
41 | include 'DAO/PessoaDAO.php';
42 |
43 | $dao = new PessoaDAO();
44 |
45 | $obj = $dao->selectById($id);
46 |
47 | return ($obj) ? $obj : new PessoaModel();
48 | }
49 |
50 | public function delete(int $id)
51 | {
52 | include 'DAO/PessoaDAO.php';
53 |
54 | $dao = new PessoaDAO();
55 |
56 | $dao->delete($id);
57 | }
58 | }
--------------------------------------------------------------------------------
/View/modules/Produto/ProdutoListar.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Lista Produtos
8 |
13 |
14 |
15 |
16 |
17 |
18 | | Delete |
19 | Id |
20 | Nome |
21 | Preço |
22 |
23 |
24 | rows as $item): ?>
25 |
26 | |
27 |
28 | X
29 |
30 | |
31 |
32 | = $item->id ?> |
33 |
34 |
35 | = $item->nome ?>
36 | |
37 |
38 | = $item->preco ?> |
39 |
40 |
41 |
42 |
43 |
44 | rows) == 0): ?>
45 |
46 | | Nenhum registro encontrado. |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/Model/FuncionarioModel.php:
--------------------------------------------------------------------------------
1 | id))
16 | {
17 | $dao->insert($this);
18 |
19 | } else
20 | {
21 | $dao->update($this);
22 | }
23 | }
24 |
25 | /**
26 | * Método que encapsula a chamada a DAO e que abastecerá a propriedade rows;
27 | * Esse método é importante pois como a model é "vista" na View a propriedade
28 | * $rows será acessada e possibilitará listar os registros vindos do banco de dados
29 | */
30 | public function getAllRows()
31 | {
32 | include 'DAO/FuncionarioDAO.php';
33 |
34 | $dao = new FuncionarioDAO();
35 |
36 | $this->rows = $dao->select();
37 | }
38 |
39 | public function getById(int $id)
40 | {
41 | include 'DAO/FuncionarioDAO.php';
42 |
43 | $dao = new FuncionarioDAO();
44 |
45 | $obj = $dao->selectById($id);
46 |
47 | return ($obj) ? $obj : new FuncionarioModel();
48 | }
49 |
50 | public function delete(int $id)
51 | {
52 | include 'DAO/FuncionarioDAO.php';
53 |
54 | $dao = new FuncionarioDAO();
55 |
56 | $dao->delete($id);
57 | }
58 | }
--------------------------------------------------------------------------------
/Controller/CategoriaProdutoController.php:
--------------------------------------------------------------------------------
1 | getAllRows();
13 |
14 | include 'View/modules/CategoriaProduto/CategoriaProdutoListar.php';
15 | }
16 |
17 | //rota form
18 | public static function form()
19 | {
20 | include 'Model/CategoriaProdutoModel.php';
21 | $model = new CategoriaProdutoModel();
22 |
23 | if(isset($_GET['id']))
24 | $model = $model->getById( (int) $_GET['id']);
25 | include 'View/modules/CategoriaProduto/CategoriaProdutoCadastro.php';
26 | }
27 |
28 | //rota save
29 |
30 | public static function save()
31 | {
32 | include 'Model/CategoriaProdutoModel.php';
33 |
34 | $categoriaproduto = new CategoriaProdutoModel;
35 | $categoriaproduto->id = $_POST['id'];
36 | $categoriaproduto->descricao = $_POST['descricao'];
37 |
38 |
39 | $categoriaproduto->save();
40 | header("Location: /categoria_produto");
41 | }
42 |
43 | //rota deletar
44 | public static function delete()
45 | {
46 | include 'Model/CategoriaProdutoModel.php';
47 |
48 | $delete = new CategoriaProdutoModel();
49 |
50 | $delete->delete( (int) $_GET['id'] );
51 |
52 | header("Location: /categoria_produto");
53 | }
54 | }
--------------------------------------------------------------------------------
/Controller/FuncionarioController.php:
--------------------------------------------------------------------------------
1 | getAllRows();
11 |
12 | include 'View/modules/Funcionario/ListaFuncionario.php';
13 | }
14 |
15 | public static function form()
16 | {
17 | include 'Model/FuncionarioModel.php';
18 | $model = new FuncionarioModel();
19 |
20 | if(isset($_GET['id']))
21 | $model = $model->getById( (int) $_GET['id']);
22 | include 'View/modules/Funcionario/FormFuncionario.php';
23 | }
24 |
25 | public static function save() {
26 |
27 | include 'Model/FuncionarioModel.php';
28 |
29 | $pessoa = new FuncionarioModel();
30 | $pessoa->id = $_POST['id'];
31 | $pessoa->nome = $_POST['nome'];
32 | $pessoa->rg = $_POST['rg'];
33 | $pessoa->cpf = $_POST['cpf'];
34 | $pessoa->data_nascimento = $_POST['data_nascimento'];
35 | $pessoa->email = $_POST['email'];
36 | $pessoa->telefone = $_POST['telefone'];
37 | $pessoa->endereco = $_POST['endereco'];
38 |
39 | $pessoa->save();
40 |
41 | header("Location: /funcionario");
42 | }
43 |
44 | public static function delete()
45 | {
46 | include 'Model/FuncionarioModel.php';
47 |
48 | $delete = new FuncionarioModel();
49 |
50 | $delete->delete( (int) $_GET['id'] );
51 |
52 | header("Location: /funcionario");
53 | }
54 | }
--------------------------------------------------------------------------------
/Controller/PessoaController.php:
--------------------------------------------------------------------------------
1 | getAllRows();
17 |
18 | include 'View/modules/Pessoa/ListaPessoas.php';
19 | }
20 |
21 | /**
22 | *
23 | */
24 | public static function form()
25 | {
26 | include 'Model/PessoaModel.php';
27 | $model = new PessoaModel();
28 |
29 | if(isset($_GET['id']))
30 | $model = $model->getById( (int) $_GET['id']);
31 | include 'View/modules/Pessoa/FormPessoa.php';
32 | }
33 |
34 | /**
35 | *
36 | */
37 | public static function save() {
38 |
39 | include 'Model/PessoaModel.php';
40 |
41 | $pessoa = new PessoaModel();
42 | $pessoa->id = $_POST['id'];
43 | $pessoa->nome = $_POST['nome'];
44 | $pessoa->rg = $_POST['rg'];
45 | $pessoa->cpf = $_POST['cpf'];
46 | $pessoa->data_nascimento = $_POST['data_nascimento'];
47 | $pessoa->email = $_POST['email'];
48 | $pessoa->telefone = $_POST['telefone'];
49 | $pessoa->endereco = $_POST['endereco'];
50 |
51 | $pessoa->save();
52 |
53 | header("Location: /pessoa");
54 | }
55 |
56 | public static function delete()
57 | {
58 | include 'Model/PessoaModel.php';
59 |
60 | $delete = new PessoaModel();
61 |
62 | $delete->delete( (int) $_GET['id'] );
63 |
64 | header("Location: /pessoa");
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/View/modules/Pessoa/ListaPessoas.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Lista Pessoas
8 |
13 |
14 |
15 |
16 |
17 |
18 | | Delete |
19 | Id |
20 | Nome |
21 | RG |
22 | CPF |
23 | TELEFONE |
24 | EMAIL |
25 | ENDERECO |
26 | DATA NASCIMENTO |
27 |
28 |
29 | rows as $item): ?>
30 |
31 | |
32 |
33 | X
34 |
35 | |
36 |
37 | = $item->id ?> |
38 |
39 |
40 | = $item->nome ?>
41 | |
42 |
43 | = $item->rg ?> |
44 | = $item->cpf ?> |
45 | = $item->telefone ?> |
46 | = $item->email ?> |
47 | = $item->endereco ?> |
48 | = $item->data_nascimento ?> |
49 |
50 |
51 |
52 |
53 | rows) == 0): ?>
54 |
55 | | Nenhum registro encontrado. |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/View/modules/Funcionario/ListaFuncionario.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Lista Funcionario
8 |
13 |
14 |
15 |
16 |
17 |
18 | | Delete |
19 | Id |
20 | Nome |
21 | RG |
22 | CPF |
23 | TELEFONE |
24 | EMAIL |
25 | ENDERECO |
26 | DATA NASCIMENTO |
27 |
28 |
29 | rows as $item): ?>
30 |
31 | |
32 |
33 | X
34 |
35 | |
36 |
37 | = $item->id ?> |
38 |
39 |
40 | = $item->nome ?>
41 | |
42 |
43 | = $item->rg ?> |
44 | = $item->cpf ?> |
45 | = $item->telefone ?> |
46 | = $item->email ?> |
47 | = $item->endereco ?> |
48 | = $item->data_nascimento ?> |
49 |
50 |
51 |
52 |
53 | rows) == 0): ?>
54 |
55 | | Nenhum registro encontrado. |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/DAO/CategoriaProdutoDAO.php:
--------------------------------------------------------------------------------
1 | conexao = new PDO($dsn, $user, $pass);
14 | }
15 |
16 | public function insert(CategoriaProdutoModel $model)
17 | {
18 | $sql = "INSERT INTO categoria_produto
19 | (descricao)
20 | VALUES
21 | (?) ";
22 |
23 | $stmt = $this->conexao->prepare($sql);
24 | $stmt->bindValue(1, $model->descricao);
25 | $stmt->execute();
26 | }
27 |
28 | public function update(CategoriaProdutoModel $model)
29 | {
30 | $sql = "UPDATE categoria_produto SET descricao=? WHERE id=? ";
31 |
32 | $stmt = $this->conexao->prepare($sql);
33 | $stmt->bindValue(1, $model->descricao);
34 | $stmt->bindValue(3, $model->id);
35 | $stmt->execute();
36 | }
37 |
38 | public function select(){
39 | $sql = "SELECT * FROM categoria_produto";
40 |
41 | $stmt = $this->conexao->prepare($sql);
42 | $stmt->execute();
43 |
44 | return $stmt->fetchAll(PDO::FETCH_CLASS);
45 | }
46 |
47 | public function selectById(int $id){
48 | include_once 'Model/CategoriaProdutoModel.php';
49 |
50 | $sql = "SELECT * FROM categoria_produto WHERE id = ?";
51 |
52 | $stmt = $this->conexao->prepare($sql);
53 | $stmt->bindValue(1, $id);
54 | $stmt->execute();
55 |
56 | return $stmt->fetchObject("CategoriaProdutoModel");
57 | }
58 |
59 | public function delete(int $id)
60 | {
61 | $sql = "DELETE FROM categoria_produto WHERE id = ?";
62 |
63 | $stmt = $this->conexao->prepare($sql);
64 | $stmt->bindValue(1, $id);
65 | $stmt->execute();
66 | }
67 | }
--------------------------------------------------------------------------------
/DAO/ProdutoDAO.php:
--------------------------------------------------------------------------------
1 | conexao = new PDO($dsn, $user, $pass);
14 | }
15 |
16 | public function insert(ProdutoModel $model)
17 | {
18 | $sql = "INSERT INTO produto
19 | (nome, preco)
20 | VALUES
21 | (?, ?) ";
22 |
23 | $stmt = $this->conexao->prepare($sql);
24 | $stmt->bindValue(1, $model->nome);
25 | $stmt->bindValue(2, $model->preco);
26 | $stmt->execute();
27 | }
28 |
29 | public function update(ProdutoModel $model)
30 | {
31 | $sql = "UPDATE produto SET nome=?, preco=? WHERE id=? ";
32 |
33 | $stmt = $this->conexao->prepare($sql);
34 | $stmt->bindValue(1, $model->nome);
35 | $stmt->bindValue(2, $model->preco);
36 | $stmt->bindValue(3, $model->id);
37 | $stmt->execute();
38 | }
39 |
40 | public function select(){
41 | $sql = "SELECT id, nome, preco FROM produto";
42 |
43 | $stmt = $this->conexao->prepare($sql);
44 | $stmt->execute();
45 |
46 | return $stmt->fetchAll(PDO::FETCH_CLASS);
47 | }
48 |
49 | public function selectById(int $id){
50 | include_once 'Model/ProdutoModel.php';
51 |
52 | $sql = "SELECT id, nome, preco FROM produto WHERE id = ?";
53 |
54 | $stmt = $this->conexao->prepare($sql);
55 | $stmt->bindValue(1, $id);
56 | $stmt->execute();
57 |
58 | return $stmt->fetchObject("ProdutoModel");
59 | }
60 |
61 | public function delete(int $id)
62 | {
63 | $sql = "DELETE FROM produto WHERE id = ?";
64 |
65 | $stmt = $this->conexao->prepare($sql);
66 | $stmt->bindValue(1, $id);
67 | $stmt->execute();
68 | }
69 | }
--------------------------------------------------------------------------------
/View/modules/Pessoa/FormPessoa.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Cadastro de Pessoa
8 |
14 |
15 |
16 |
17 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/View/modules/Funcionario/FormFuncionario.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Cadastro de Funcionario
8 |
14 |
15 |
16 |
17 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 | include 'Controller/PessoaController.php';
9 | include 'Controller/ProdutoController.php';
10 | include 'Controller/FuncionarioController.php';
11 | include 'Controller/CategoriaProdutoController.php';
12 |
13 | switch($uri_parse)
14 | {
15 | case '/pessoa':
16 | PessoaController::index();
17 | break;
18 |
19 | case '/pessoa/form':
20 | PessoaController::form();
21 | break;
22 |
23 | case '/pessoa/save':
24 | PessoaController::save();
25 | break;
26 |
27 | case '/pessoa/delete':
28 | PessoaController::delete();
29 | break;
30 |
31 | ## ROTAS PARA PRODUTO
32 |
33 | case '/produto':
34 | ProdutoController::index();
35 | break;
36 |
37 | case '/produto/form':
38 | ProdutoController::form();
39 | break;
40 |
41 | case '/produto/save':
42 | ProdutoController::save();
43 | break;
44 |
45 | case '/produto/delete':
46 | ProdutoController::delete();
47 | break;
48 |
49 | ## ROTAS PARA FUNCIONARIO
50 |
51 | case '/funcionario':
52 | FuncionarioController::index();
53 | break;
54 |
55 | case '/funcionario/form':
56 | FuncionarioController::form();
57 | break;
58 |
59 | case '/funcionario/save':
60 | FuncionarioController::save();
61 | break;
62 |
63 | case '/funcionario/delete':
64 | FuncionarioController::delete();
65 | break;
66 |
67 | ## ROTAS PARA CATEGORIA PRODUTO
68 |
69 | case '/categoria_produto':
70 | CategoriaProdutoController::index();
71 | break;
72 |
73 | case '/categoria_produto/form':
74 | CategoriaProdutoController::form();
75 | break;
76 |
77 | case '/categoria_produto/save':
78 | CategoriaProdutoController::save();
79 | break;
80 |
81 | case '/categoria_produto/delete':
82 | CategoriaProdutoController::delete();
83 | break;
84 |
85 | default:
86 | echo "erro 404";
87 | break;
88 | }
--------------------------------------------------------------------------------
/DAO/FuncionarioDAO.php:
--------------------------------------------------------------------------------
1 | conexao = new PDO($dsn, $user, $pass);
14 | }
15 |
16 | public function insert(FuncionarioModel $model)
17 | {
18 | $sql = "INSERT INTO funcionario
19 | (nome, rg, cpf, email, data_nascimento, telefone, endereco)
20 | VALUES
21 | (?, ?, ?, ?, ?, ?, ?) ";
22 |
23 | $stmt = $this->conexao->prepare($sql);
24 |
25 | $stmt->bindValue(1, $model->nome);
26 | $stmt->bindValue(2, $model->rg);
27 | $stmt->bindValue(3, $model->cpf);
28 | $stmt->bindValue(4, $model->email);
29 | $stmt->bindValue(5, $model->data_nascimento);
30 | $stmt->bindValue(6, $model->telefone);
31 | $stmt->bindValue(7, $model->endereco);
32 | $stmt->execute();
33 |
34 | }
35 |
36 | public function update(FuncionarioModel $model)
37 | {
38 | $sql = "UPDATE funcionario SET nome=?, rg=?, cpf=?, email=?, data_nascimento=?, telefone=?, endereco=? WHERE id=? ";
39 |
40 | $stmt = $this->conexao->prepare($sql);
41 | $stmt->bindValue(1, $model->nome);
42 | $stmt->bindValue(2, $model->rg);
43 | $stmt->bindValue(3, $model->cpf);
44 | $stmt->bindValue(4, $model->email);
45 | $stmt->bindValue(5, $model->data_nascimento);
46 | $stmt->bindValue(6, $model->telefone);
47 | $stmt->bindValue(7, $model->endereco);
48 | $stmt->bindValue(8, $model->id);
49 | $stmt->execute();
50 | }
51 |
52 | public function select()
53 | {
54 | $sql = "SELECT * FROM funcionario";
55 |
56 | $stmt = $this->conexao->prepare($sql);
57 | $stmt->execute();
58 |
59 | return $stmt->fetchAll(PDO::FETCH_CLASS);
60 | }
61 |
62 | public function selectById(int $id)
63 | {
64 | include_once 'Model/FuncionarioModel.php';
65 |
66 | $sql = "SELECT * FROM funcionario WHERE id = ?";
67 |
68 | $stmt = $this->conexao->prepare($sql);
69 | $stmt->bindValue(1, $id);
70 | $stmt->execute();
71 |
72 | return $stmt->fetchObject("FuncionarioModel");
73 | }
74 |
75 |
76 |
77 | public function delete(int $id)
78 | {
79 | $sql = "DELETE FROM funcionario WHERE id = ?";
80 |
81 | $stmt = $this->conexao->prepare($sql);
82 | $stmt->bindValue(1, $id);
83 | $stmt->execute();
84 | }
85 |
86 | }
--------------------------------------------------------------------------------
/DAO/PessoaDAO.php:
--------------------------------------------------------------------------------
1 | conexao = new PDO($dsn, $user, $pass);
14 | }
15 |
16 | public function insert(PessoaModel $model)
17 | {
18 | //Trecho de código SQL com marcadores ? para substituição posterior, no prepare
19 | $sql = "INSERT INTO pessoa
20 | (nome, rg, cpf, email, data_nascimento, telefone, endereco)
21 | VALUES
22 | (?, ?, ?, ?, ?, ?, ?) ";
23 |
24 | //Declaração da variável stmt que conterá a montagem da consulta.
25 | $stmt = $this->conexao->prepare($sql);
26 |
27 | // Nesta etapa os bindValue são responsáveis por receber um valor e trocar em uma determinada posição
28 | $stmt->bindValue(1, $model->nome);
29 | $stmt->bindValue(2, $model->rg);
30 | $stmt->bindValue(3, $model->cpf);
31 | $stmt->bindValue(4, $model->email);
32 | $stmt->bindValue(5, $model->data_nascimento);
33 | $stmt->bindValue(6, $model->telefone);
34 | $stmt->bindValue(7, $model->endereco);
35 | // Ao fim, onde todo SQL está montando, executamos a consulta.
36 | $stmt->execute();
37 |
38 | }
39 |
40 | public function update(PessoaModel $model)
41 | {
42 | $sql = "UPDATE pessoa SET nome=?, rg=?, cpf=?, email=?, data_nascimento=?, telefone=?, endereco=? WHERE id=? ";
43 |
44 | $stmt = $this->conexao->prepare($sql);
45 | $stmt->bindValue(1, $model->nome);
46 | $stmt->bindValue(2, $model->rg);
47 | $stmt->bindValue(3, $model->cpf);
48 | $stmt->bindValue(4, $model->email);
49 | $stmt->bindValue(5, $model->data_nascimento);
50 | $stmt->bindValue(6, $model->telefone);
51 | $stmt->bindValue(7, $model->endereco);
52 | $stmt->bindValue(8, $model->id);
53 | $stmt->execute();
54 | }
55 |
56 | //Método que retorna todas os registros da tabela pessoa no banco de dados.
57 | public function select()
58 | {
59 | $sql = "SELECT * FROM pessoa";
60 |
61 | $stmt = $this->conexao->prepare($sql);
62 | $stmt->execute();
63 |
64 | // retorna um array com as linhas retornadas da consulta. Observe que
65 | // o array é um array de objetos. Os objetos são do tipo stdClass e
66 | // foram criados automaticamente pelo método fetchAll do PDO.
67 | return $stmt->fetchAll(PDO::FETCH_CLASS);
68 | }
69 |
70 | public function selectById(int $id)
71 | {
72 | include_once 'Model/PessoaModel.php';
73 |
74 | $sql = "SELECT * FROM pessoa WHERE id = ?";
75 |
76 | $stmt = $this->conexao->prepare($sql);
77 | $stmt->bindValue(1, $id);
78 | $stmt->execute();
79 |
80 | return $stmt->fetchObject("PessoaModel");
81 | }
82 |
83 |
84 |
85 | public function delete(int $id)
86 | {
87 | $sql = "DELETE FROM pessoa WHERE id = ?";
88 |
89 | $stmt = $this->conexao->prepare($sql);
90 | $stmt->bindValue(1, $id);
91 | $stmt->execute();
92 | }
93 |
94 | }
--------------------------------------------------------------------------------