Advertisement
Guest User

shakir - php - dbquery

a guest
Feb 11th, 2018
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. //auth for db
  2.  
  3. $server  = "localhost";
  4. $pass = "db4115944";
  5. $user = "db4115944";
  6. $dbn  = "db4115944";
  7.  
  8. $r =  new mysqli($server, $user,$pass,$dbn);
  9.  
  10. if ($r-> connect_error){
  11.  
  12. die("Connection failed :".$r->connect_error);
  13. }
  14.  
  15. $sql = "SELECT firstname, surname FROM nametable";
  16. $result = $r->query($sql);
  17. //prints html table with mysql element
  18. if ($result->num_rows > 0) {
  19.  
  20. echo "<br><br><br>"."<table border='4' class='stats' cellspacing='0'>"."<tr>"."<th>"."First Name"."</th>"."<th>"."Surname"."</th>"."</tr>";
  21.  
  22.     while($row = $result->fetch_assoc()) {
  23.  
  24. echo "<tr>"."<td>". $row["firstname"]."</td>"."<td>".$row["surname"]."</td>"."</tr>";
  25.     }
  26. } else {
  27.     echo "<br>"."0 results from db";
  28. }
  29. //cannot close connection as it eliminated db conn and somehow ends sessions
  30. //$conn->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement