Guest User

Untitled

a guest
Mar 3rd, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2. //Initalize server credential varables
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "root";
  6. $dbname = "infx2070";
  7.  
  8. //create connection
  9. $conn = new mysqli($servername, $username, $password, $infx2070);
  10.  
  11. //check for connection status
  12. if($conn->connect_error){
  13. die("connection failed: " . $conn->connect_error . "<br>");
  14. } else {
  15. echo "Connection successful! <br>";
  16. }
  17.  
  18. $sql = "SELECT C_id, first_name, last_name, Comment FROM Comments";
  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 "id: " . $row["C_id"] . " - Name: " . $row["first_name"] . " "
  25. . $row["last_name"] . " - Comment: " . $row["Comment"] . "<br>";
  26. }
  27. } else {
  28. echo "0 result <br>";
  29. }
  30.  
  31. $conn->close();
  32. echo "Connection closed <br>";
  33. ?>
Add Comment
Please, Sign In to add comment