Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DBClass {
- $servername = "localhost";
- $username = "root";
- $password = "anything";
- try {
- $bdd = new PDO('mysql:host=$servername;dbname=myDB;charset=utf8', $username, $password); //connexion à MySQL
- // set the PDO error mode to exception
- $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "Connected successfully";
- $stmt = $bdd->prepare("SELECT Place, Address, Date FROM MyDB");
- $stmt->execute();
- }
- catch(Exception $e)
- {
- die('Connection failed:' . $e->getMessage()); //En cas d'erreur, on affiche un message et on arrete tout
- }
- }
- $reponse = $bdd->query('SELECT * FROM myDB'); //récupération de tout le contenu de la table MyDB
- // On affiche chaque entrée une à une
- while ($donnees = $reponse->fetch())
- {
- ?>
- <p>
- <strong>Name</strong> : <?php echo $donnees['Place']; ?><br />
- </p>
- <?php
- }
- $reponse->closeCursor(); // Termine le traitement de la requête
- ?>
Add Comment
Please, Sign In to add comment