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.
This commit is contained in:
2010-09-16 23:05:46 +01:00
parent 1c402a8aef
commit e4071badd9

View File

@@ -32,12 +32,21 @@ 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) {
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;
}