I'm trying to make a PDO query to display data. This is what i have done so far :
in my models/pdo, i created a class with this:
<?php
class VengeanceUsers {
public static function getNumbersOfregistered()
{
$connexion = new PDO("mysql:host=localhost ;dbname=databasetest", 'root', 'passe'); // connexion à la BDD
$var_dump($connexion);
exit();
$resultats=$connexion->query("SELECT COUNT (*) FROM ope_tartine_nl "); // on va chercher tous les membres de la table qu'on trie par ordre croissant
return $resultats;
}
}
?>
In my controller:
$this->view->nb_users = VengeanceUsers::getNumbersOfregistered();
In my view:
Nombre d'inscrits : <?php echo $this->nb_users; ?><br/>
I don't have anything displayed... Can anyone help me on this ? Thanks in advance
$resultats=$connexion->query("SELECT COUNT (*) FROM ope_tartine_nl "); // on va chercher tous les membres de la table qu'on trie par ordre croissant
This only gives you the result object of the query.
You have to actually fetch the row from your result.
$resultats=$connexion->query("SELECT COUNT (*) FROM ope_tartine_nl "); // on va chercher tous les membres de la table qu'on trie par ordre croissant
$numRows = $resultats->fetchColumn();
return $numRows;
This should fix it
exit();
out. $var_dump($connexion);
you need to remove $
in the beginning. For #3 you can use:
$sth = $connexion->query("SELECT COUNT (*) FROM ope_tartine_nl "); // get statement
$resultats = $sth->fetchColumn(); // get data
return $resultats;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.