Can someone help me whit these errors ?
My table is like this in my database :
Here is my code :
Level, Type these are MySQL reserved keywords. You need to enclosed them properly
<?php
try{
$bdd=new PDO('mysql:host=localhost;dbname=cmadatabase','root','@Rugby3390', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$reponse= $bdd->query('SELECT `IR`,`Level`,`Type`,`ToBeAnalyzed`,`Supplier`,`Consequences`,`Remarks`,SUM(`Level`,`Type`,`Supplier`) AS sommeLvlTypeSup FROM andgate GROUP BY `IR`,`Level`,`Type`,`ToBeAnalyzed`,`Supplier`,`Consequences`,`Remarks` ORDER BY SUM(`Level`,`Type`,`Supplier`) ASC');
while ($donnees = $reponse->fetch())
{
echo '<p>'.$donnees['IR'].','.$donnees['Level'].','.$donnees['Type'].','.$donnees['ToBeAnalyzed'].','.$donnees['Supplier'].','.$donnees['Consequences'].','.$donnees['Remarks'].','.$donnees['sommeLvlTypeSup'].'<p>';
}
} catch(PDOExpection $px) {
echo $px->getMessage();
}
?>
Reference: https://dev.mysql.com/doc/refman/5.7/en/keywords.html
1st : Alias name in order by
clause ORDER BY sommeLvlTypeSup ASC
2nd : Type
is mysql keyword
. so try to enclose
the backticks
around table name
column
name
try
{
$bdd=new PDO('mysql:host=localhost;dbname=cmadatabase','root','@Rugby3390');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$reponse= $bdd->query('SELECT `IR`,`Level`,`Type`,`ToBeAnalyzed`,
`Supplier`,`Consequences`,`Remarks`,
SUM(`Level`,`Type`,`Supplier`) AS sommeLvlTypeSup
FROM `andgate`
GROUP BY `IR`,`Level`,`Type`,`ToBeAnalyzed`,
`Supplier`,`Consequences`,`Remarks`
ORDER BY sommeLvlTypeSup ASC');
while ($donnees = $reponse->fetch()){
echo '<p>'.$donnees['IR'].','.$donnees['Level'].','.$donnees['Type'].','.$donnees['ToBeAnalyzed'].','.$donnees['Supplier'].','.$donnees['Consequences'].','.$donnees['Remarks'].','.$donnees['sommeLvlTypeSup'].'<p>';
}
}
catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage();}