Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2. //1. Database conecction
  3. $dbhost = "localhost";
  4. $dbuser = "caferiej_insta";
  5. $dbpass = "rockyjr718";
  6. $dbname = "caferiej_data_database";
  7. $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  8.  
  9. //Test is connection works
  10. if(mysqli_connect_errno()){
  11. die("connection failed" . mysqli_connect_error() . "(". mysqli_connect_errno() .")");
  12. }
  13. ?>
  14.  
  15. <?php
  16. //2. Perform query
  17. $query = "SELECT * FROM cafe";
  18. $result = mysqli_query($connection, $query);
  19. //test if query error
  20. if(!$result){
  21. die("query failed");
  22. }
  23. ?>
  24.  
  25. <?php
  26. //3.Use returned data
  27. while($row = mysqli_fetch_row($result)){
  28. //get the first row and assign to the variable, loop increment
  29. var_dump($row);
  30. //output from each row
  31. echo "<hr />";
  32. //horizontal line tag
  33. }
  34. ?>
  35. <?php
  36. //4. Release the data
  37. mysqli_free_result($result);
  38. ?>
  39.  
  40. <!DOCTYPE html>
  41. <html>
  42. <head>
  43. <title>database</title>
  44. </head>
  45. <body>
  46.  
  47. </body>
  48. </html>
  49.  
  50. <?php
  51. //5. Close the connection
  52. mysqli_close($connection);
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement