From e4071badd99a52c350715b3f12bc07bb68207cbb Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Thu, 16 Sep 2010 23:05:46 +0100 Subject: [PATCH] Adds support for lists returned by selectAssoc The column values parameter to RippingCluster_Database::selectAssoc() now accepts an array of columns instead of a single value. If a scalar is provided, the value is returned as a simple associative array; if an array is provided, the full list of columns requested is returned as a nested associative array. --- lib/RippingCluster/Database.class.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/RippingCluster/Database.class.php b/lib/RippingCluster/Database.class.php index 9ff1b14..49f0b13 100644 --- a/lib/RippingCluster/Database.class.php +++ b/lib/RippingCluster/Database.class.php @@ -32,11 +32,20 @@ class RippingCluster_Database { $this->dbh = null; } - public function selectAssoc($sql, $key_col, $value_col) { + public function selectAssoc($sql, $key_col, $value_cols) { $results = array(); foreach ($this->dbh->query($sql) as $row) { - $results[$row[$key_col]] = $row[$value_col]; + if (is_array($value_cols)) { + $values = array(); + foreach ($value_cols as $value_col) { + $values[$value_col] = $row[$value_col]; + } + + $results[$row[$key_col]] = $values; + } else { + $results[$row[$key_col]] = $row[$value_col]; + } } return $results;