td06 - exercices
This commit is contained in:
90
afficheMatieres.php
Normal file
90
afficheMatieres.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* PARAMETRES DE CONNEXION A LA BASE DE DONNEES
|
||||
*/
|
||||
$ip = 'localhost';
|
||||
$user = 'phpapp';
|
||||
$pass = 'myphp';
|
||||
$database = 'universite';
|
||||
|
||||
// Définition de la source des données pour PDO
|
||||
$dsn = "mysql:host=$ip;dbname=$database;charset=utf8mb4";
|
||||
|
||||
// Création de l'objet $dbh, de type PDO, qui est la ressource d'accès à la base
|
||||
try {
|
||||
$dbh = new PDO($dsn, $user, $pass);
|
||||
} catch (PDOException $e) {
|
||||
die("Erreur de connexion : ".$e->getMessage());
|
||||
}
|
||||
|
||||
// Il est vérifié que le domaine a bien été fourni à la page.
|
||||
if($_GET['domain'] != null) {
|
||||
|
||||
?>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<td><b>Intitulé</b></td>
|
||||
<td><b>Description</b></td>
|
||||
</thead>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* ICI, écrire une requête SQL permettant d'obtenir les informations suivantes de la table matiere :
|
||||
* mNom, mDescription
|
||||
* Cette requête ne doit retourner que les entrées correspondant au domaine obtenu dans $_GET
|
||||
*/
|
||||
|
||||
/**
|
||||
* EXECUTER ensuite la requête et stocker le résultat dans $stmtMatieres
|
||||
*/
|
||||
|
||||
// Les résultats de la requête sont parcourus un par un, sous forme d'un tableau associatif $row
|
||||
while ($row = $stmtMatieres->fetch()) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td><!-- Afficher ICI le nom de la matière --></td>
|
||||
<td><!-- Afficher ICI sa description --></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</table>
|
||||
|
||||
<?php
|
||||
}
|
||||
else{
|
||||
header('Location : index.php');
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<br>
|
||||
<a href="index.php">Retour à l'accueil</a>
|
||||
<?php
|
||||
|
||||
// Fermeture de la connexion
|
||||
$stmtDomains = null;
|
||||
$pdoStmt = null;
|
||||
$dbh = null;
|
||||
|
||||
|
||||
// Petite aide au développement
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<h3>SUIVI DES VARIABLES POUR DEVELOPPEMENT : </h3>";
|
||||
echo "<h4>GLOBALS : </h4>";
|
||||
echo '<pre>';
|
||||
print_r($GLOBALS);
|
||||
Reference in New Issue
Block a user