I want to retrieve some Data from database using custom PHP MVC.
I created a Controller File
semestres.php
class Semestres extends Controller {
function __construct(){
parent::__construct();
}
public function index(){
$this->view->fetchSemestres = $this->model->fetchSemestres();
$this->view->render('semestres/index');
}
}
a Model
semestres_model.php
class Semestres_Model extends Model{
public function __construct(){
parent::__construct();
}
public function fetchSemestres(){
$stmt = $this->db->prepare("SELECT * FROM semestres");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
return $stmt->fetchAll();
}
}
and a View file index inside the folder semestre.
foreach($this->fetchSemestres AS $key=>$value){
echo $value['intitule_semestre']."<br>";
}
But it gives me nothing !!!
The print_r($this->fetchSemestres) gives me an empty array
Array ( )
// Update:
Database connection:
class Database extends PDO{
public function __construct(){
parent::__construct('mysql:host:localhost;dbname:planingexams', 'root', '');
}
}
Model.php
class Model{
function __construct(){
$this->db = new Database();
}
}