I’ve wrote a code to select data from my database, and I test if the statement returns something or no with fetchColumn() and I display the results if it’s not null using a loop with fetch(). But event when the results exist it soesn’t show me anything.. Here’s my code :
$req = $bdd->prepare('SELECT NOM_Etudiant, PRENOM_Etudiant FROM Etudiant WHERE CNE_Etudiant = :cnev AND PASS_Etudiant = :passv');
$req->execute(array('cnev' => $cne, 'passv' => $pass));
$count = $req->fetchColumn();
if(!$count) {
header('Location: authentification_etud.php?status=invalid');
}
else {
// Doesn't work
while ($donnees = $req->fetch())
{
echo '<strong>Bienvenue </strong>' . $donnees['NOM_Etudiant'] . ' ' . $donnees['PRENOM_Etudiant'] . ' ! ' ;
}
}
Do you know why it doesn’t work ? Thank you 🙂
You should use a
rowCount()method to determine the number of rows notfetchColumn().fetchColumn()will actually advance the pointer in the result set to where you will no longer have access to the first row of data.Notice the big red warning on this page http://php.net/manual/en/pdostatement.fetchcolumn.php