Commit 722c6952dd797dd5c230acc58c0f3cb026d731b1
1 parent
8a700ed0
schools: Nicer exception handling
Showing
1 changed file
with
62 additions
and
38 deletions
Show diff stats
pages/schools.php
1 | +<h2>Liste écoles participantes</h2> | |
1 | 2 | <?php |
2 | -require_once("creds.php"); | |
3 | +require_once ("creds.php"); | |
4 | + | |
5 | +try { | |
6 | + | |
7 | + $link = @mysql_connect(__MYSQL_HOSTNAME__, __MYSQL_USERNAME__, __MYSQL_PASSWORD__); | |
8 | + | |
9 | + if (!$link) { | |
10 | + throw new Exception('Impossible de se connecter : ' . mysql_error()); | |
11 | + } | |
12 | + | |
13 | + if (!mysql_select_db('crep', $link)) { | |
14 | + throw new Exception('Selection de la base de donnees impossible'); | |
15 | + } | |
16 | + mysql_query("SET NAMES 'utf8'"); | |
17 | + $requete = "SELECT DISTINCT `nom`, `circonscription`, `adresse`, `enseignant`, `contact` FROM `school` ORDER BY nom ASC"; | |
18 | + | |
19 | + $resultat = mysql_query($requete); | |
20 | + | |
21 | + mysql_close($link); | |
3 | 22 | ?> |
4 | -<h2>Liste écoles participantes</h2> | |
5 | 23 | |
6 | 24 | <center> |
7 | 25 | <table class="table table-striped table-responsive table-bordered"> |
... | ... | @@ -11,48 +29,54 @@ require_once("creds.php"); |
11 | 29 | <th>Nom de l'école</th> |
12 | 30 | <th>Circonscription</th> |
13 | 31 | <th>Contact</th> |
14 | -<!-- <th>Enseignant</th> | |
15 | - <th>Contact</th> --> | |
32 | +<?php /* | |
33 | + <th>Enseignant</th> | |
34 | + <th>Contact</th> | |
35 | +*/ ?> | |
16 | 36 | </tr> |
17 | 37 | </thead> |
18 | 38 | </div > |
19 | 39 | <tbody> |
20 | 40 | <?php |
21 | -$link = mysql_connect(__MYSQL_HOSTNAME__, __MYSQL_USERNAME__, __MYSQL_PASSWORD__) | |
22 | - or die("Impossible de se connecter : " . mysql_error()); | |
23 | - | |
24 | -if(!mysql_select_db('crep', $link)) | |
25 | -{ | |
26 | - echo 'Selection de la base de donnees impossible'; | |
27 | - exit; | |
28 | -} | |
29 | -mysql_query("SET NAMES 'utf8'"); | |
30 | -$requete = "SELECT DISTINCT `nom`, `circonscription`, `adresse`, `enseignant`, `contact` FROM `school` ORDER BY nom ASC"; | |
31 | -$resultat = mysql_query($requete); | |
32 | - | |
33 | -while ($row = mysql_fetch_assoc($resultat)) | |
34 | -{ | |
35 | - echo '<tr>'; | |
36 | - echo '<td>'; | |
37 | - echo '<p>'.$row['nom'].'</p>'; | |
38 | - echo '</td>'; | |
39 | - echo '<td>'; | |
40 | - echo '<p>'.$row['circonscription'].'</p>'; | |
41 | - echo '</td>'; | |
42 | - echo '<td>'; | |
43 | - echo '<p>'.$row['adresse'].'</p>'; | |
44 | - echo '</td>'; | |
45 | - // echo '<td>'; | |
46 | - // echo '<p>'.$row['enseignant'].'</p>'; | |
47 | - // echo '</td>'; | |
48 | - // echo '<td>'; | |
49 | - // echo '<p>'.$row['contact'].'</p>'; | |
50 | - // echo '</td>'; | |
51 | -echo '</tr>'; | |
52 | -} | |
53 | - | |
54 | -mysql_close($link); | |
41 | + | |
42 | + while ($row = mysql_fetch_assoc($resultat)) { | |
43 | + echo '<tr>'; | |
44 | + echo '<td>'; | |
45 | + echo '<p>' . $row['nom'] . '</p>'; | |
46 | + echo '</td>'; | |
47 | + echo '<td>'; | |
48 | + echo '<p>' . $row['circonscription'] . '</p>'; | |
49 | + echo '</td>'; | |
50 | + echo '<td>'; | |
51 | + echo '<p>' . $row['adresse'] . '</p>'; | |
52 | + echo '</td>'; | |
53 | + | |
54 | + // echo '<td>'; | |
55 | + // echo '<p>'.$row['enseignant'].'</p>'; | |
56 | + // echo '</td>'; | |
57 | + // echo '<td>'; | |
58 | + // echo '<p>'.$row['contact'].'</p>'; | |
59 | + // echo '</td>'; | |
60 | + echo '</tr>'; | |
61 | + } | |
55 | 62 | ?> |
63 | + | |
56 | 64 | </tbody> |
57 | 65 | </table> |
58 | 66 | </center> |
67 | +<?php | |
68 | +} | |
69 | +catch(Exception $e) { | |
70 | +?> | |
71 | +<div class="alert alert-danger" role="alert"> | |
72 | +Impossible d'afficher la liste des écoles participantes.<br/> | |
73 | +Merci de rééssayer ultérieurement. | |
74 | +</div> | |
75 | +<!-- | |
76 | +<?php | |
77 | +echo $e; | |
78 | +?> | |
79 | +--> | |
80 | +<?php | |
81 | +} | |
82 | +?> | ... | ... |