criada a função para editar e deletar os dados do banco maria
This commit is contained in:
@@ -48,13 +48,67 @@ class Controller extends DBA{
|
||||
//print_r($this->res);
|
||||
//return $this->res;
|
||||
}
|
||||
public function getPais(){
|
||||
$this->sql = "SELECT * FROM usuarios";
|
||||
public function getPais($CD_ALUNO){
|
||||
$this->sql = "SELECT * FROM usuarios WHERE CD_ALUNO = ?";
|
||||
$this->stmt = self::$instMARIA->prepare($this->sql);
|
||||
$this->stmt->bindValue(1,$CD_ALUNO);
|
||||
$this->stmt->execute();
|
||||
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $this-> res;
|
||||
}
|
||||
public function deletaPais($CPF){
|
||||
$this->sql = "DELETE FROM usuarios WHERE CPF = ?";
|
||||
$this->stmt = self::$instMARIA->prepare($this->sql);
|
||||
$this->stmt->bindValue(1,$CPF);
|
||||
$this->stmt->execute();
|
||||
if($this->stmt){
|
||||
echo 'deletado com sucesso';
|
||||
}else{
|
||||
echo 'erro';
|
||||
}
|
||||
}
|
||||
public function inserirPais(){
|
||||
$CD_ALUNO = $_POST['CD_ALUNO'];
|
||||
$CPF = $_POST['CPF'];
|
||||
$NOME = $_POST['NOME'];
|
||||
$SENHA = $_POST['SENHA'];
|
||||
$PARENTESCO = $_POST['PARENTESCO'];
|
||||
$DATA_CADASTRO = $_POST['DATA_CADASTRO'];
|
||||
$CONDICAO = $_POST['CONDICAO'];
|
||||
if($CONDICAO=='NOVO'){
|
||||
$this->sql = "INSERT INTO usuarios (CD_ALUNO, CPF, NOME, SENHA, PARENTESCO, DATA_CADASTRO, CONDICAO) VALUES (:CD_ALUNO, :CPF, :NOME, :SENHA, :PARENTESCO, :DATA_CADASTRO, :CONDICAO)";
|
||||
$this->stmt = self::$instMARIA->prepare($this->sql);
|
||||
$this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO);
|
||||
$this->stmt->bindValue(':CPF', $CPF);
|
||||
$this->stmt->bindValue(':NOME', $NOME);
|
||||
$this->stmt->bindValue(':SENHA', $SENHA);
|
||||
$this->stmt->bindValue(':PARENTESCO', $PARENTESCO);
|
||||
$this->stmt->bindValue(':DATA_CADASTRO', $DATA_CADASTRO);
|
||||
$this->stmt->bindValue(':CONDICAO', $CONDICAO);
|
||||
$this->stmt->execute();
|
||||
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $this-> res;
|
||||
}
|
||||
if($this->stmt){
|
||||
echo 'cadastrado com sucesso';
|
||||
}else{
|
||||
echo 'erro';
|
||||
}
|
||||
}else{
|
||||
$this->sql = "UPDATE usuarios SET CD_ALUNO = :CD_ALUNO, NOME = :NOME, SENHA = :SENHA, PARENTESCO = :PARENTESCO, DATA_CADASTRO = :DATA_CADASTRO, CONDICAO = :CONDICAO WHERE CPF = :CPF";
|
||||
$this->stmt = self::$instMARIA->prepare($this->sql);
|
||||
$this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO);
|
||||
$this->stmt->bindValue(':CPF', $CPF);
|
||||
$this->stmt->bindValue(':NOME', $NOME);
|
||||
$this->stmt->bindValue(':SENHA', $SENHA);
|
||||
$this->stmt->bindValue(':PARENTESCO', $PARENTESCO);
|
||||
$this->stmt->bindValue(':DATA_CADASTRO', $DATA_CADASTRO);
|
||||
$this->stmt->bindValue(':CONDICAO', $CONDICAO);
|
||||
$this->stmt->execute();
|
||||
if($this->stmt){
|
||||
echo 'editado com sucesso';
|
||||
}else{
|
||||
echo 'erro';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DBA{
|
||||
|
||||
@@ -2,13 +2,20 @@
|
||||
namespace app\controllers;
|
||||
|
||||
class PaisController{
|
||||
public function index(){
|
||||
public function index($params){
|
||||
$cod = $params->CD_ALUNO;
|
||||
$Log = new Controller();
|
||||
$Logins = $Log->getPais();
|
||||
$Logins = $Log->getPais($cod);
|
||||
echo json_encode($Logins);
|
||||
return json_encode($Logins);
|
||||
}
|
||||
public function store(){
|
||||
var_dump('store do login');
|
||||
public function insert(){
|
||||
$Log = new Controller();
|
||||
$Logins = $Log->inserirPais();
|
||||
}
|
||||
public function deleta($params){
|
||||
$cpf = $params->CPF;
|
||||
$Log = new Controller();
|
||||
$Logins = $Log->deletaPais($cpf);
|
||||
}
|
||||
}
|
||||
11
index.php
11
index.php
@@ -65,4 +65,13 @@ try{
|
||||
|
||||
//dados alunos
|
||||
//http://localhost:8000/aluno?NR_LOGRADOURO=715
|
||||
//http://localhost:8000/aluno?NOME=JOAO%20MIGUEL%20DE
|
||||
//http://localhost:8000/aluno?NOME=JOAO%20MIGUEL%20DE
|
||||
|
||||
//inserir
|
||||
//http://localhost:8000/inserirpais
|
||||
|
||||
//DADOS PAIS
|
||||
//http://localhost:8000/pais?CD_ALUNO=70B81220937CED736CA3A7D462E3FF6A
|
||||
|
||||
//DELELA PAIS
|
||||
//http://localhost:8000/deleta?CPF=123
|
||||
@@ -24,9 +24,10 @@ $router= [
|
||||
"/login" => fn()=> load("LoginController","index"),
|
||||
"/aluno" => fn()=> load("AlunoController","index"),
|
||||
"/pais" => fn()=> load("PaisController","index"),
|
||||
"/deleta" => fn()=> load("PaisController","deleta"),
|
||||
],
|
||||
"POST"=>[
|
||||
"/login" => fn()=> load("LoginController","store")
|
||||
"/inserirpais" => fn()=> load("PaisController","insert")
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user