Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>mysql example</title>
  6. </head>
  7. <body>
  8. <?php
  9. $servername = "localhost";
  10. $username = "student";
  11. $password = "";
  12. $dbname = "employees";
  13. // Create connection
  14. $conn = new mysqli ( $servername, $username, $password, $dbname );
  15. // Check connection
  16. if ($conn->connect_error) {
  17. die ( "Connection failed: " . $conn->connect_error );
  18. }
  19. $sql = "SELECT * from employees limit 10";
  20. $result = $conn->query ( $sql );
  21. echo "<table border='1' cellpadding='2' cellspacing='2'";
  22. echo "<tr><td>First Name</td><td>Second Name</td>";
  23. if ($result->num_rows > 0) {
  24. // output data of each row
  25. while ( $row = $result->fetch_assoc () ) {
  26. echo "<tr><td> " . $row ["first_name"] . "</td><td>" . $row ["last_name"] . "</td>";
  27. }
  28. } else {
  29. echo "0 results";
  30. }
  31. $conn->close ();
  32. ?>
  33.  
  34. </body>
  35. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement