summaryrefslogtreecommitdiff
path: root/sqlbox/locallib.php
diff options
context:
space:
mode:
Diffstat (limited to 'sqlbox/locallib.php')
-rw-r--r--sqlbox/locallib.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/sqlbox/locallib.php b/sqlbox/locallib.php
index 3820cec..f335b9a 100644
--- a/sqlbox/locallib.php
+++ b/sqlbox/locallib.php
@@ -38,3 +38,20 @@ defined('MOODLE_INTERNAL') || die();
//function sqlbox_do_something_useful(array $things) {
// return new stdClass();
//}
+
+function db_table_from_query($db, $query) {
+ $table = new html_table;
+ $result = pg_query($db, $query);
+ if (!$result)
+ error("Query failed: ".pg_last_error($db));
+
+ $table = new html_table;
+ $n = pg_num_fields($result);
+ for ($i = 0; $i < $n; $i++)
+ $table->head[] = pg_field_name($result, $i);
+ $table->align = array_fill(0, $n, 'left');
+ while ($row = pg_fetch_row($result))
+ $table->data[] = $row;
+
+ return $table;
+}