From 3faf64c6a1e0cbd4f880da951775c41fb8a6f0ab Mon Sep 17 00:00:00 2001 From: Josh Grams Date: Sat, 22 Aug 2009 13:29:23 -0400 Subject: [PATCH] * db.php (db_get_assoc, db_get_assocs): new functions to ease use of new template code. --- db.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/db.php b/db.php index 4a58db8..f39d5e0 100644 --- a/db.php +++ b/db.php @@ -166,6 +166,22 @@ function db_get_rows($table, $columns, $where = '') { return $rows; } +# like db_get_rows, but return array of hashes. +function db_get_assocs($table, $columns, $where = '') { + $args = func_get_args(); + $args = array_slice($args, 3); + $result = db_send_get($table, $columns, $where, $args); + + $rows = array(); + while($row = mysql_fetch_assoc($result)) { + $rows[] = $row; + } + + mysql_free_result($result); + + return $rows; +} + function db_get_column($table, $columns, $where = '') { $args = func_get_args(); $args = array_slice($args, 3); @@ -193,6 +209,19 @@ function db_get_row($table, $columns, $where = '') { return $row; } +# like db_get_row, but return a hash. +function db_get_assoc($table, $columns, $where = '') { + $args = func_get_args(); + $args = array_slice($args, 3); + $result = db_send_get($table, $columns, $where, $args); + + $row = mysql_fetch_assoc($result); + + mysql_free_result($result); + + return $row; +} + function db_get_value($table, $columns, $where = '') { $args = func_get_args(); $args = array_slice($args, 3); -- 1.7.10.4