Guest User

Untitled

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