Advertisement
Guest User

oop

a guest
Jun 2nd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. index.php
  2.  
  3. <!DOCTYPE HTML>
  4.  
  5. <html lang="pl">
  6. <head>
  7. <meta charset="UTF-8"/>
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
  9. <link href="style.css" rel="stylesheet" type="text/css"/>
  10.  
  11. </head>
  12. <body>
  13.  
  14. <h1>Lista ksiazek</h1>
  15.  
  16. <?php
  17.  
  18. include ('baza.php');
  19.  
  20. $tbl = $pdo->query ('SELECT * FROM `regal`');
  21.  
  22. echo '<table border="3pxl">';
  23. echo '<tr>';
  24.  
  25. echo '<th>Autor</th>';
  26. echo '<th>Tytul</th>';
  27. echo '<th>Recenzja</th>';
  28. echo '<th>Opcje</th>';
  29. echo '</tr>';
  30.  
  31.  
  32. foreach ($tbl ->fetchAll() as $value){
  33.  
  34. echo '<tr>';
  35.  
  36. echo '<td>' . $value[ 'autor' ] . '</td>';
  37. echo '<td>' . $value[ 'tytul' ] . '</td>';
  38. echo '<td>' . $value[ 'recenzja' ] . '</td>';
  39. echo '<td>' . $value[ 'id' ] . '</td>';
  40.  
  41.  
  42. echo '</tr>';
  43.  
  44.  
  45.  
  46. }
  47.  
  48. echo '</table>';
  49.  
  50.  
  51. ?>
  52.  
  53.  
  54. </body>
  55. </html>
  56.  
  57. baza.php
  58.  
  59. <?php
  60.  
  61. require_once "connect.php";
  62.  
  63. try{
  64.  
  65. $pdo = new PDO('mysql: host='.$host.'; dbname='.$db_name.';port='.$port, $db_user, $db_password );
  66.  
  67. $pdo->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC );
  68.  
  69.  
  70. } catch(PDOException $e){
  71. echo 'Polaczenie nie moglo zostac utworzone <br/>';
  72. }
  73.  
  74.  
  75. ?>
  76.  
  77. connect.php
  78.  
  79. <?php
  80.  
  81. $host = "localhost";
  82. $db_user = "root";
  83. $db_password = "";
  84. $db_name = "ksiazki";
  85. $port="";
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement