Guest User

Untitled

a guest
Aug 11th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. //Table in DB:
  2. create table a_first (request varchar(30), answer varchar(30)) ;
  3. insert into a_first values ('qwe','asd') ;
  4. insert into a_first values ('rty','fgh') ;
  5.  
  6. //Contains of /usr/share/php/db.php
  7. $servername="ip_address";
  8. $username="mysql_user";
  9. $password="mysql_pass";
  10. $dbname="dbname" ;
  11.  
  12. //Contains of /usr/share/nginx/html/test.php
  13. <?php
  14. echo "<html><header></header><body>";
  15. require_once 'db.php';
  16.  
  17. echo "test page" ;
  18. echo "<br>" ;
  19.  
  20.  
  21. $conn = mysql_connect($servername, $username, $password);
  22.  
  23. if (!$conn) {
  24. die('cani't connect: ' . mysql_error());
  25. }
  26.  
  27. $db_selected = mysql_select_db($dbname, $conn);
  28. if (!$db_selected) {
  29. die ('can't select DB: ' . mysql_error());
  30. }
  31.  
  32. $sql = "select * from a_first; " ;
  33. $result = mysql_query($sql);
  34.  
  35. if (!$result) {
  36. die('SQL error: ' . mysql_error());
  37. }
  38.  
  39. while ($row = mysql_fetch_assoc($result)) {
  40. echo $row['request']." - ".$row['answer']." n";
  41. echo "<br>n" ;
  42. }
  43.  
  44. mysql_free_result($result);
  45.  
  46. echo "</body></html>";
  47. ?>
Add Comment
Please, Sign In to add comment