Advertisement
Tr22

Untitled

Feb 22nd, 2020
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <?php
  6. $servername = "localhost";
  7. $username = "username";
  8. $password = "password";
  9. $dbname = "myDB";
  10.  
  11. // Create connection
  12. $conn = new mysqli($servername, $username, $password, $dbname);
  13. // Check connection
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. $sql = "SELECT id, firstname, lastname FROM MyGuests";
  19. $result = $conn->query($sql);
  20.  
  21. if ($result->num_rows > 0) {
  22. // output data of each row
  23. while($row = $result->fetch_assoc()) {
  24. echo "<br> id: ". $row["id"]. " - Name: ". $row["firstname"]. " " . $row["lastname"] . "<br>";
  25. }
  26. } else {
  27. echo "0 results";
  28. }
  29.  
  30. $conn->close();
  31. ?>
  32.  
  33. </body>
  34. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement