Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define('DB','sistema_postgres');
- define('HOST','localhost');
- define('USER','postgres');
- define('PASS','123');
- require_once 'config.php';
- class Database {
- private $db;
- private $host;
- private $user;
- private $pass;
- private $conn;
- public function __construct(){
- $this->host = HOST;
- $this->db = DB;
- $this->user = USER;
- $this->pass = PASS;
- $this->conn = new PDO("pgsql:host={$this->host};port=5432;dbname={$this->db};user={$this->user};password={$this->pass}");
- }
- protected function getConn(){
- return $this->conn;
- }
- }
- require_once('database.php');
- class TurmaDAO extends Database implements IDAO{
- private $turma;
- private $db;
- public function __construct($turma=null) {
- if(isset($turma)){
- $this->setTurma($turma);
- }
- parent::__construct();
- $this->db = parent::getConn();
- }
- public function listAll() {
- $stmt = $this->db->prepare('SELECT * FROM turma');
- $stmt->execute();
- try{
- $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
- }
- catch(PDOException $e){
- echo $e->getMessage();
- die();
- }
- return $rs;
- }
- }
- require_once 'TurmaDAO.php';
- $t = new TurmaDAO();
- $rs = $t->listAll();
- var_dump($rs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement