i would like to print the result of an SQL request in my view in PHP (from scratch), I use PDO and mySQL
But I have this error :
Nombre d'incidents :
Fatal error: Uncaught Error: Call to a member function nbIncidents() on array in C:Applicationswamp64wwwportailviewsincidentincidents.view.php:7 Stack trace: #0 C:Applicationswamp64wwwportailcontrollersIncidentController.controller.php(47): require() #1 C:Applicationswamp64wwwportailindex.php(169): IncidentController->afficherIncidents() #2 {main} thrown in C:Applicationswamp64wwwportailviewsincidentincidents.view.php on line 7
My code :
in my Controller :
public function IncidentsCount()
{
$incidents = $this->incidentManager->nbIncidents();
require "views/incident/incidents.view.php";
}
my Manager :
public function nbIncidents(){
$req ="SELECT COUNT(*) FROM `incidents` WHERE clos = :nonclos";
$stmt = $this->getBdd()->prepare($req);
$stmt->bindValue(":nonclos", 0, PDO::PARAM_STR);
$stmt->execute();
$nbIncidents = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $nbIncidents;
}
my View :
<p>Nombre d'incidents : <?php $incidents->nbIncidents(); ?></p>
I also tested to make a simpler function to see, like this :
public function nbIncidents(){
$nbIncidents = 777;
echo $nbIncidents;
}
And I have the same error.
If someone knows how resolve this error, thanks in advance.
Sincerely,
GM