有人可以帮我解决这些错误吗?
我的数据库中的表格如下:
这是我的代码:
<?php
$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>';
}
?>
非常感谢
答案 0 :(得分:0)
第一名 order by
子句ORDER BY sommeLvlTypeSup ASC
第二名: Type
为mysql keyword
。所以尝试enclose
backticks
table name
column
名称
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();}
答案 1 :(得分:0)
级别,键入这些是MySQL保留的关键字。你需要把它们妥善包围
<?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();
}
?>