summaryrefslogtreecommitdiff
path: root/sqlbox/locallib.php
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:46:44 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:47:38 +0100
commit744c06b8fcfc3a2d1540eeef44c84522b58475af (patch)
tree887dae694c6788a2436107a82c48d84d749c421f /sqlbox/locallib.php
parent639db3eee5df60f520b33dcb0c8f0e1ffc80fd49 (diff)
downloadsqltutor-plugin-744c06b8fcfc3a2d1540eeef44c84522b58475af.tar.gz
sqltutor-plugin-744c06b8fcfc3a2d1540eeef44c84522b58475af.tar.bz2
sqltutor-plugin-744c06b8fcfc3a2d1540eeef44c84522b58475af.zip
sqlbox: Move db_table_from_query to locallib.php
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;
+}