summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sqlbox/view.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/sqlbox/view.php b/sqlbox/view.php
index 5f0e4a0..d095376 100644
--- a/sqlbox/view.php
+++ b/sqlbox/view.php
@@ -84,7 +84,20 @@ if (isset($data->sqlbox_query)) {
if (!db)
error("Failed to connect to sqlbox db");
- $result = pg_query($db, $data->sqlbox_query);
+ $table = db_get_table_from_query($db, $data->sqlbox_query);
+
+ echo html_writer::table($table);
+
+ pg_close($db);
+}
+
+// Finish the page
+echo $OUTPUT->footer();
+
+
+function db_get_table_from_query($db, $query) {
+ $table = new html_table;
+ $result = pg_query($db, $query);
if (!$result)
error("Query failed: ".pg_last_error($db));
@@ -96,10 +109,6 @@ if (isset($data->sqlbox_query)) {
while ($row = pg_fetch_row($result))
$table->data[] = $row;
- echo html_writer::table($table);
-
- pg_close($db);
+ return $table;
}
-// Finish the page
-echo $OUTPUT->footer();