dataBaseConnection.php
Código PHP:
Ver original
abstract class dataBaseConnection{ /* *propiedades */ protected function open_connection(){ $this->pdo= new PDO('mysql:host='.self::$host.';dbname='.$this->dbname , self::$user, self::$pass); } protected function close_connection(){ $this->pdo=null; } }
newsModel.php
Código PHP:
me podrian aconsejar, si lo dejo como lo tengo o como estatico, gracias. Ver original
require_once 'dataBaseConnection.php'; class newsModel extends datBaseConnection{ /* *propiedades */ function __construct(){ $this->dbname="database"; } public function getAllNews(){ $this->query= "SELECT * FROM noticias ORDER BY id DESC"; $this->open_connection(); $this->rows=$this->pdo->query($this->query)->fetchAll(); return $this->rows; } }