Advertisement
Guest User

rtyrtythrtyryr

a guest
Jan 14th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Data Base Connection</title>
  5. <link rel="stylesheet" type="text/css"
  6. href="CSS/Style1.CSS" title="style1">
  7. </head>
  8. <body>
  9. <h1 style="text-align:center">Connecting and reading from Database</h1>
  10. <?php
  11. //create connection variables
  12. $dbServer="localhost:3307";
  13. $dbUser="root";
  14. $dbPassword="";
  15. $dbName="SKDB2019";
  16.  
  17. //create connection
  18. $conn=new mysqli($dbServer,$dbUser,$dbPassword,$dbName);
  19. if($conn->connect_error==true){
  20. die("Connection failed error ".$conn->$connect_error);
  21. }else{
  22. echo "<h3>Connection successful</h3>";
  23. }
  24. //sql statement to select all records
  25. $sql="SELECT * FROM STUDENT";
  26. //execute query
  27. $result = $conn->query($sql);
  28. echo"<table border='2'style='margin-left:auto;margin-right:auto;'>";
  29. echo"<th>ID</th><NAME</th><th>PHONE</th><th>CITY</th>";
  30. if($result->num_rows>0){
  31. while($row=$result->fetch_assoc()){
  32. echo"<tr><td>".$row["ID"]."</td>";
  33. echo"<td>".$row["Name"]."</td>";
  34. echo"<td>".$row["Phone"]."</td>";
  35. echo"<td>".$row["City"]."</td></tr>";
  36. }
  37. echo "</table>";
  38. }else{
  39. echo "<h3>No records in the table</h3>";
  40. }
  41. ?>
  42. </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement