80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?php
|
|
namespace app\controllers;
|
|
use League\Plates\Engine;
|
|
use PDO;
|
|
class Controller extends DBA{
|
|
public static function view(string $view, array $data = []){
|
|
|
|
$viewsPath = dirname(__FILE__,2)."/views";
|
|
|
|
if(!file_exists($viewsPath . DIRECTORY_SEPARATOR . $view.".php")){
|
|
throw new \Exception("A view {$view} não existe");
|
|
}
|
|
|
|
$templates = new Engine($viewsPath);
|
|
echo $templates-> render($view,$data);
|
|
}
|
|
public function getLogin($NO_USERNAME){
|
|
if(!$NO_USERNAME==''){
|
|
$this->sql = "SELECT * FROM LOGIN WHERE NO_USERNAME = ?";
|
|
$this->stmt = self::$inst->prepare($this->sql);
|
|
$this->stmt->bindValue(1,$NO_USERNAME);
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetch(PDO::FETCH_OBJ);
|
|
return $this-> res;
|
|
}else{
|
|
//caso o id não foi passado recebe essa mensagem
|
|
die('informação incompleta...');
|
|
}
|
|
}
|
|
public function getAlunos($NOME){
|
|
//CRIADO PARA TESTE COM PARAMETRO
|
|
if(!$NOME==''){
|
|
$this->sql = "SELECT * FROM ALUNO WHERE NO_ALUNO LIKE ?";
|
|
$this->stmt = self::$inst->prepare($this->sql);
|
|
$this->stmt->bindValue(1,"%".$NOME."%");
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
return $this-> res;
|
|
}else{
|
|
//caso o id não foi passado recebe essa mensagem
|
|
die('informação incompleta...');
|
|
}
|
|
//FUNCIONANDO PARA TODA A TABELA ALUNO
|
|
//$this->sql = "SELECT * FROM ALUNO";
|
|
//$this->stmt = self::$inst->prepare($this->sql);
|
|
//$this->stmt -> execute();
|
|
//$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;
|
|
}
|
|
}
|
|
|
|
class DBA{
|
|
protected $stmt, $sql, $res;
|
|
protected static $inst;
|
|
//faz a chamada da instancia da conexão com o banco de dados
|
|
function __construct(){
|
|
try{
|
|
if(self::$inst === null){
|
|
//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";
|
|
return self::$inst;
|
|
}catch(\PDOException $e){
|
|
//retorna caso de erro na conexão
|
|
echo "Connection failed: " . $e->getMessage();
|
|
}
|
|
}
|
|
} |