语法错误,查询sql

时间:2017-07-10 11:45:08

标签: php sql

这是我的代码:

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 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 (PDOException $e) { echo 'Connection failed: ' . $e->getMessage();}

?>

这是我的错误:

  

连接失败:SQLSTATE [42000]:语法错误或访问冲突:1064 Erreur de syntaxepr�sde&#39; Type,Supplier)AS sommeLvlTypeSup FROM andgate GROUP BY IR,Level,Type,ToBeAnalyz&#39; �la ligne 1

你可以帮忙吗?我没有看到我的语法错误在哪里?

很多

2 个答案:

答案 0 :(得分:0)

尝试改变

"ORDER BY SUM(Level,Type,Supplier)" 

"ORDER BY sommeLvlTypeSup"

理论上,GROUP / ORDER BY SUM(..)不起作用。

答案 1 :(得分:0)

尝试ORDER BY sommeLvlTypeSup而不是SUM(Level,Type,Supplier)