Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dbconnection = pg_connect("host=localhost user=test-user dbname=maindb password=test-user");
- executeQueryAndPrintResult("SELECT * FROM maintable");
- executeQueryAndPrintResult("SELECT * FROM maintable WHERE cost < 800");
- executeQueryAndPrintResult("SELECT * FROM maintable WHERE cost > 800");
- function executeQueryAndPrintResult($query){
- echo $query;
- $result = pg_query($query) or die('Query failed: ' . pg_last_error());
- echo "<table>\n";
- while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
- echo "\t<tr>\n";
- foreach ($line as $col_value) {
- echo "\t\t<td>$col_value</td>\n";
- }
- echo "\t</tr>\n";
- }
- echo "</table>\n";
- echo "<br>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement