Advertisement
haqon

Untitled

May 5th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2. $dbconnection = pg_connect("host=localhost user=test-user dbname=maindb password=test-user");
  3.  
  4. executeQueryAndPrintResult("SELECT * FROM maintable");
  5. executeQueryAndPrintResult("SELECT * FROM maintable WHERE cost < 800");
  6. executeQueryAndPrintResult("SELECT * FROM maintable WHERE cost > 800");
  7.  
  8.  
  9. function executeQueryAndPrintResult($query){
  10. echo $query;
  11.  
  12. $result = pg_query($query) or die('Query failed: ' . pg_last_error());
  13.  
  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. }
  23. echo "</table>\n";
  24. echo "<br>";
  25. }
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement