Guest User

Untitled

a guest
Oct 9th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. class DBClass {
  3.  
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "anything";
  7.  
  8.  
  9. try {
  10. $bdd = new PDO('mysql:host=$servername;dbname=myDB;charset=utf8', $username, $password); //connexion à MySQL
  11. // set the PDO error mode to exception
  12. $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13. echo "Connected successfully";
  14. $stmt = $bdd->prepare("SELECT Place, Address, Date FROM MyDB");
  15. $stmt->execute();
  16. }
  17. catch(Exception $e)
  18. {
  19. die('Connection failed:' . $e->getMessage()); //En cas d'erreur, on affiche un message et on arrete tout
  20. }
  21. }
  22.  
  23. $reponse = $bdd->query('SELECT * FROM myDB'); //récupération de tout le contenu de la table MyDB
  24. // On affiche chaque entrée une à une
  25. while ($donnees = $reponse->fetch())
  26. {
  27. ?>
  28. <p>
  29. <strong>Name</strong> : <?php echo $donnees['Place']; ?><br />
  30. </p>
  31. <?php
  32. }
  33.  
  34. $reponse->closeCursor(); // Termine le traitement de la requête
  35.  
  36. ?>
Add Comment
Please, Sign In to add comment