Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2. ini_set ("display_errors", "1");
  3.  
  4. error_reporting(E_ALL);
  5. // Connecting, selecting database
  6. $dbconn = pg_connect("host=localhost dbname=skript user=postgres password=postgres")
  7. or die('Could not connect: ' . pg_last_error());
  8.  
  9. // Performing SQL query
  10. $query = 'SELECT * FROM authors';
  11. $result = pg_query($query) or die('Query failed: ' . pg_last_error());
  12.  
  13. // Printing results in HTML
  14. echo "<table>\n";
  15. while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
  16. echo "\t<tr>\n";
  17. foreach ($line as $col_value) {
  18. echo "\t\t<td>$col_value</td>\n";
  19. }
  20. echo "\t</tr>\n";
  21. }
  22. echo "</table>\n";
  23.  
  24. // Free resultset
  25. pg_free_result($result);
  26.  
  27. // Closing connection
  28. pg_close($dbconn);
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement