PDO Exception errors

后端 未结 2 905
感情败类
感情败类 2021-01-17 01:55

Can someone help me whit these errors ?

My table is like this in my database :

Here is my code :



        
相关标签:
2条回答
  • 2021-01-17 02:09

    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

    0 讨论(0)
  • 2021-01-17 02:23

    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();}
    
    0 讨论(0)
提交回复
热议问题