8eec3f20e5c9321700aa619d8e64621f9169df82
[TD_BDD.git] / TD5 / PHP / testmysql.php
1 <html>
2 <body>
3 <?php
4 if( $id = mysql_connect($_SERVER['dbHost'],$_SERVER['dbLogin'],$_SERVER['dbPass']) ) {
5 if( $id_db = mysql_select_db($_SERVER['dbBd']) ) {
6 echo 'Connexion a la base.<br><br>';
7 $requete = "SELECT NumCl, NomCl, CodePosteCl, VilleCl FROM CLIENTS";
8 if($result = mysql_query($requete)) {
9 echo "<table border=1>\n";
10 echo "<tr><td>Code_CL</td><td>Nom</td><td>Rue</td><td>Ville</td></tr>\n";
11 while($ligne = mysql_fetch_row($result)) {
12 $code = $ligne[0];
13 $nom = $ligne[1];
14 $rue = $ligne[2];
15 $ville = $ligne[3];
16 echo "<tr><td>$code</td><td>$nom</td><td>$rue</td><td>$ville</td></tr>\n";
17 }
18 echo "</table>\n";
19 } else {
20 echo 'Erreur de requete';
21 }
22 } else {
23 die('Echec de connexion a la base');
24 }
25 mysql_close();
26 echo '<br>Deconnexion.';
27 } else {
28 die('Echec de connexion au serveur de bases de donnees');
29 }
30 ?>
31 </body>
32 </html>
33