- Application 01
Énoncé
- Vous pouvez visualiser l'énoncé de l'exercice
Solution
Page: connect.php
<?php $host = 'localhost'; $dbname = 'notes_des_etudiants'; $user = 'root'; $passwd = '123'; ?>Page: connectionDB.php
<?php include("connect.php"); try { $pdo = new PDO("mysql:host=".$host.";dbname=".$dbname, $user, $passwd); //echo "Connexion réalisée avec succès"; } catch (PDOException $e) { print "Erreur !: " . $e->getMessage() . "
"; die(); } ?>Page:affichageEtudiants.php
<?php <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> <link type="text/css" rel="stylesheet" href="style.css"> <title>Exercice PDO</title> </head> <body> <h1>Affichage des étudiants</h1> <?php include('connexionDB.php'); echo "<div class='container'>"; echo "<h3>Utilisation des marqueurs interrogatifs</h3>"; // Requêtes préparées avec ? echo "<h6>Utilisation des marqueurs interrogatifs (homme)</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE ?"); $stmt->execute(['Homme']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; ////////////////////////////////////////////////////////////// echo "<h6>Utilisation des marqueurs interrogatifs (homme deuxième caractère 'h')</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE ? and prenomEtud like ?"); $stmt->execute(['Homme','__h%']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; echo "<h6>Utilisation des marqueurs interrogatifs (Femme)</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE ?"); $stmt->execute(['Femme']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; echo "<h6>Utilisation des marqueurs interrogatifs (femme deuxième caractère 'h')</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE ? and prenomEtud like ?"); $stmt->execute(['Femme','__h%']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; ////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// echo "<h3>Utilisation des marqueurs nominatifs</h3>"; // Requêtes préparées avec ? echo "<h6>Utilisation des marqueurs interrogatifs (homme)</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE :genre"); $stmt->execute(['genre'=>'Homme']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; ////////////////////////////////////////////////////////////// echo "<h6>Utilisation des marqueurs nominatifs (homme deuxième caractère 'h')</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE :genre and prenomEtud like :prenom"); $stmt->execute(['genre'=>'Homme','prenom'=>'__h%']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; echo "<h6>Utilisation des marqueurs interrogatifs (Femme)</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE :genre"); $stmt->execute(['genre'=>'Femme']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; echo "<h6>Utilisation des marqueurs interrogatifs (femme deuxième caractère 'h')</h6>"; $stmt=$pdo-> prepare("SELECT * FROM etudiants where genre LIKE :genre and prenomEtud like :prenom"); $stmt->execute(['genre'=>'Femme','prenom'=>'__h%']); echo "<table><thead> <tr><th>Numéro</th><th>Nom</th><th>Prénom</th><th>Genre</th><th>Date de naissance</th><th>Rue</th><th>Cp</th><th>Ville</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td></tr>"; } echo "</tbody></table>"; echo "</div>"; ?> <!-- Optional JavaScript; choose one of the two! --> <!-- Option 1: Bootstrap Bundle with Popper --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> <!-- Option 2: Separate Popper and Bootstrap JS --> <!-- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script> --> </body> </html> ?>Page:style.css
@font-face { font-family:'ma-police-ttf'; src:local('ma-police'), url('ma_police.ttf') format('truetype'); } p {font-family:ma-police-ttf} h1{color: #58acfa; text-align:center;} h6{color: #58acfa; text-align:left; padding-top: 20px;} table { border:solid 3px #58acfa; background-color:#FC9; width:80%; border-collapse:collapse; } th { text-align:center; font-weight:bold; background-color:purple; color:#FFF; border-color:#FFF; } td { text-align:justify; background-color:#CFC; empty-cells:hide; } td,th { border:solid 1px #000; margin:0; vertical-align:middle; } caption { caption-side:bottom; text-align:left; color:#060; } a:hover { color: cyan; font-size: 200%; } i{color:red;} .button { background-color: #1c87c9; box-shadow: 0 5px 0 #105cad; color: white; padding: 1em 1.5em; position: relative; text-decoration: none; display: inline-block; } /*.cellule { width : 195px; margin-left : 5px; margin-top : 5px; border : rgb(31, 16, 236) 1px solid; height: 20px; display: table-cell; } .colonne{ float: left; }*/- Application 02
Énoncé
- Vous pouvez visualiser l'énoncé de l'exercice
Solution
script base de données
- Télécharger la la base de données depuis votre interface phpMyAdmin puis l'importer
- Vous pouvez suivre ces instructions pour importer votre base de données:
- Ouvrez phpMyAdmin.
- Cliquez sur le nom de la base de données qui recevra les informations importées. La page se rafraîchira pour afficher les informations relatives à la base de données sélectionnée.
- Cliquez sur l’onglet Importer.
- Cliquez sur le bouton Afficher de la section "Fichier à importer" (File to import).
- Votre navigateur vous invitera à repérer sur votre ordinateur le fichier de la base de données.
- Une fois le fichier repéré et sélectionné, le champ "Emplacement du fichier texte" (Location of the text file) affichera le chemin du fichier de la base de données.
- Cliquez sur le bouton Exécuter.
- Une fois le téléversement du fichier terminé, les données et la structure qu’il contient seront immédiatement disponibles pour utilisation dans la base de données.
Page: header.php
<?php include('connexionDB.php'); ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> <!-- Bootstrap Font Icon CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"> <title>Gestion des apprenants</title> <nav class="navbar navbar-light bg-light mb-4"> <div class="container"> <a class="navbar-brand" href="#"> <img src="images/bootstrap-logo.svg" alt="" width="30" height="24"> </a> </div> </nav> </head> <body>Page: footer.php
<!-- Optional JavaScript; choose one of the two! --> <!-- Option 1: Bootstrap Bundle with Popper --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> <!-- Option 2: Separate Popper and Bootstrap JS --> <!-- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script> --> </body> </html>Page: rechercheApprenant.php
<?php if(isset($_POST["btnAfficher"]) && isset($_POST["txtAfficher"])) { $apprenant=$_POST["txtAfficher"]; $stmt=$pdo-> prepare("SELECT * FROM apprenants where cinapprenant LIKE ?"); $stmt->execute(['%'.$apprenant.'%']); echo "<table class='table table-striped'><thead> <tr><th>CIN</th> <th>Prénom</th><th>Nom</th><th>Date de naissance</th> <th>Civilité</th> <th>Adresse</th> <th>Adresse mail</th><th>Gouvernorat</th> <th>Groupe</th></tr></thead><tbody>"; while ($ligne=$stmt->fetch()) { echo "<tr><td>". $ligne[0]."</td>". "<td>". $ligne[1]."</td>". "<td>". $ligne[2]."</td>". "<td>". $ligne[3]."</td>". "<td>". $ligne[4]."</td>". "<td>". $ligne[5]."</td>". "<td>". $ligne[6]."</td>". "<td>". $ligne[7]."</td>". "<td>". $ligne[8]."</td></tr>"; } echo "</tbody></table>"; echo "</div>"; } ?>Page: rechercheMultiple.php
<?php include('header.php'); ?> <div class="container"> <div class="card " style="border-width: 1px;"> <div class="card-header bg-primary text-white"> <h5>Rechercher des apprenants</h5> </div> <div class="card-body "> <form class="row row-cols-lg-12 pt-0 align-items-center" method="post" action="#"> <div class="col-md-2"> <input type="text" class="form-control" placeholder="Prénom" name="txtPrenom"> </div> <div class="col-md-2"> <input type="text" class="form-control" placeholder="Nom" name="txtNom"> </div> <div class="col-md-2"> <input type="date" class="form-control" placeholder="Naissance" name="txtDteNaissance"> </div> <div class="col-md-2"> <select name="civilite" class="form-select"> <option selected>Choisir...</option> <option>Homme</option> <option>Femme</option> </select> </div> <div class="col-md-2"> <select name="gouvernorat" class="form-select"> <option selected>Choisir...</option> <option>Tunis</option> <option>Nabeul</option> </select> </div> <div class="col-md-2"> <button type="submit" name="btnAfficher" class="btn btn-primary"><span class="bi-search"></span>Rechercher</button> </div> </form> </div> </div> <div class="card mt-4" style="border-width: 1px;"> <div class="card-header bg-primary text-white"> <h5>Résultat de votre recherche</h5> </div> <div class="card-body "> <?php include('affichageMultiple.php'); ?> </div> </div> </div> <?php include('footer.php'); ?>