From 5b019c94ce1d733196906cb31beca357384a06f5 Mon Sep 17 00:00:00 2001 From: Reginaldo Date: Fri, 16 Jun 2023 17:10:52 -0300 Subject: [PATCH] =?UTF-8?q?cria=C3=A7=C3=A3o=20da=20conex=C3=A3o=20com=20o?= =?UTF-8?q?=20banco=20mobile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/classes/config.php | 1 - app/controllers/AlunoController.php | 4 ++-- app/controllers/Controller.php | 20 +++++++++++++++----- app/controllers/PaisController.php | 14 ++++++++++++++ index.php | 3 ++- routes/router.php | 3 ++- 6 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 app/controllers/PaisController.php diff --git a/app/classes/config.php b/app/classes/config.php index 790933c..65250d0 100644 --- a/app/classes/config.php +++ b/app/classes/config.php @@ -5,5 +5,4 @@ define('SENHA','K5f6rt9Y'); define('BANCO','/bases/educa/iracemapolis/SISTEMA.FDB'); define('STR_BD','firebird:dbname='.SERVIDOR.'/'.PORTA.':'.BANCO.';charset=UTF-8'); - //será mudada depois o banco para a cidade desejada dinâmicamente \ No newline at end of file diff --git a/app/controllers/AlunoController.php b/app/controllers/AlunoController.php index d7605c1..729899e 100644 --- a/app/controllers/AlunoController.php +++ b/app/controllers/AlunoController.php @@ -3,9 +3,9 @@ namespace app\controllers; class AlunoController{ public function index($params){ - $numero = $params->NR_LOGRADOURO; + $nome = $params->NOME; $Con = new Controller(); - $Alunos = $Con->getAlunos($numero); + $Alunos = $Con->getAlunos($nome); echo json_encode($Alunos); return json_encode($Alunos); } diff --git a/app/controllers/Controller.php b/app/controllers/Controller.php index d3630b7..266b976 100644 --- a/app/controllers/Controller.php +++ b/app/controllers/Controller.php @@ -27,12 +27,12 @@ class Controller extends DBA{ die('informação incompleta...'); } } - public function getAlunos($NR_LOGRADOURO){ + public function getAlunos($NOME){ //CRIADO PARA TESTE COM PARAMETRO - if(!$NR_LOGRADOURO==''){ - $this->sql = "SELECT * FROM ALUNO WHERE NR_LOGRADOURO = ?"; + if(!$NOME==''){ + $this->sql = "SELECT * FROM ALUNO WHERE NO_ALUNO LIKE ?"; $this->stmt = self::$inst->prepare($this->sql); - $this->stmt->bindValue(1,$NR_LOGRADOURO); + $this->stmt->bindValue(1,"%".$NOME."%"); $this->stmt->execute(); $this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC); return $this-> res; @@ -47,6 +47,13 @@ class Controller extends DBA{ //$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC); //print_r($this->res); //return $this->res; + } + public function getPais(){ + $this->sql = "SELECT * FROM usuarios"; + $this->stmt = self::$inst->prepare($this->sql); + $this->stmt->execute(); + $this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC); + return $this-> res; } } @@ -57,7 +64,10 @@ class DBA{ function __construct(){ try{ if(self::$inst === null){ - self::$inst = new \PDO(STR_BD,USUARIO,SENHA); + //FIREBIRD + //self::$inst = new \PDO(STR_BD,USUARIO,SENHA); + //MARIADB + self::$inst = new \PDO("mysql:dbname=controledb;host=localhost;charset=utf8",'root',''); } //retorna a instancia com sucesso //echo "Connected successfully"; diff --git a/app/controllers/PaisController.php b/app/controllers/PaisController.php new file mode 100644 index 0000000..945d899 --- /dev/null +++ b/app/controllers/PaisController.php @@ -0,0 +1,14 @@ +getPais(); + echo json_encode($Logins); + return json_encode($Logins); + } + public function store(){ + var_dump('store do login'); + } +} \ No newline at end of file diff --git a/index.php b/index.php index cc49edc..49cd5d9 100644 --- a/index.php +++ b/index.php @@ -64,4 +64,5 @@ try{ //http://localhost:8000/login?NO_USERNAME=AMENEZES //dados alunos -//http://localhost:8000/aluno?NR_LOGRADOURO=715 \ No newline at end of file +//http://localhost:8000/aluno?NR_LOGRADOURO=715 +//http://localhost:8000/aluno?NOME=JOAO%20MIGUEL%20DE \ No newline at end of file diff --git a/routes/router.php b/routes/router.php index 2d7c52f..b2bb093 100644 --- a/routes/router.php +++ b/routes/router.php @@ -22,7 +22,8 @@ $router= [ "GET"=>[ "/"=> fn()=> load("HomeController","index"), "/login" => fn()=> load("LoginController","index"), - "/aluno" => fn()=> load("AlunoController","index") + "/aluno" => fn()=> load("AlunoController","index"), + "/pais" => fn()=> load("PaisController","index"), ], "POST"=>[ "/login" => fn()=> load("LoginController","store")