Advertisement
Guest User

Untitled

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