处理mysqli中的异常

时间:2018-02-16 18:07:11

标签: php mysqli

它只是我项目代码的一部分,我正在尝试在表中显示用户数据,并在出现错误时处理异常,问题是我收到mysqli错误,尽管错误已处理,任何建议处理得对吗?

  

错误:警告:mysqli_num_rows()要求参数1为mysqli_result,布尔值在第166行的C:\ wamp \ www \ ProjectFinEtude \ profAccueil.php中给出

第166行是if(mysqli_num_rows($result)>0)

我希望'try'消息'$ e'

<?php
        try{

        $query = "select * from eleve_an_cls
inner join eleve on eleve.CIN_ELEVE = eleve_an_cls.CIN_ELEVE
inner join class on class.ID_CLASS = eleve_an_cls.ID_CLASS
inner join annee_scolaire on annee_scolaire.ID_ANNEE = eleve_an_cls.ID_ANNEE
where class.ID_CLASS = $select1 and annee_scolaire.ID_ANNEE = $select2";

        $result = mysqli_query($con,$query);

        if(mysqli_num_rows($result)>0)

        {    echo"<table class='table table-bordered table-striped table-hover table-info'>";
             echo"<tr>
                <th>CIN</th>
                <th>NOM</th>
                <th>PRENOM</th>
                <th>DATE NAISSANCE</th>
                <th>FILLIERE</th>
                <th>Note</th>
                </tr>";
            while($rows=mysqli_fetch_assoc($result))
            {
                $cin     = $rows['CIN_ELEVE'];
                $nom     = $rows['NOM_ELEVE'];
                $prenom  = $rows['PRENOM_ELEVE'];
                $date    = $rows['DATENAISSANCE_ELEVE'];
                $filiere = $rows['FILIERE_ELEVE'];
                echo "<tr>
                <td>$cin</td>
                <td>$nom</td>
                <td>$prenom</td>
                <td>$date</td>
                <td>$filiere</td>
                <td><button type='submit' class='btn-sm btn-info cursor'><a>Ajouter ici</a></button></td>
                </tr>";

            }
         echo"</table>";
        }

        }

        catch(Exception $e)
        {
            echo 'Exception reçue : ',  $e->getMessage(), "\n";
        }

        ?>

0 个答案:

没有答案