Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <?php
  2. //1. Database conecction
  3. $dbhost = "localhost";
  4. $dbuser = "professor_rauch";
  5. $dbpass = "password";
  6. $dbname = "untitled_DB";
  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 table_name";
  18. $result = mysqli_query($connection, $query);
  19. //test if query error
  20. if(!$result){
  21. die("query failed");
  22. }
  23. ?>
  24.  
  25. <!DOCTYPE html>
  26. <html>
  27. <head>
  28. <title>database</title>
  29. </head>
  30. <body>
  31.  
  32. </body>
  33. </html>
  34.  
  35. <?php
  36. //5. Close the connection
  37. mysqli_close($connection);
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement