Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2.  
  3. $dsn = 'pgsql:dbname=test;host=localhost;';
  4. $user = 'postgres';
  5. $password = '?????';
  6.  
  7. try {
  8.     $dbh = new PDO($dsn, $user, $password);
  9.     $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  10.     $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.     echo "Connected";
  12.  
  13. }   catch(PDOException $e) {
  14.     echo 'Connection failed: ' .$e->getMessage();
  15. }
  16.  
  17.  
  18. // /*
  19. $calories = 150;
  20. $color = "red";
  21.  
  22. $sth = $dbh->prepare('SELECT name, color, calories FROM fruit');
  23. //$sth->bindValue(1, $calories, PDO::PARAM_INT);
  24. //$sth->bindValue(2, $color, PDO::PARAM_STR);
  25. $sth->execute();
  26.  
  27. //$test = $sth->fetch(PDO::FETCH_OBJ);
  28.  
  29. $test = $sth->fetchAll();
  30.  
  31. //print_r($test);
  32.  
  33.  
  34. // */
  35.  
  36.  
  37. ?>
  38.  
  39. <html>
  40. <head>
  41. <style type="text/css">
  42.     table, th, td {
  43.         border: 1px solid black;
  44.     }
  45. </style>
  46. </head>
  47. <body>
  48.  
  49. <table>
  50.     <thead>
  51.         <tr>
  52.             <th>Test table</th>
  53.         </tr>
  54.     </thead>
  55.     <tbody>
  56.         <tr>
  57.             <td><?php print_r($test); ?></td>
  58.         </tr>
  59.     </tbody>
  60. </table>
  61.  
  62. </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement