summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2007-10-06 21:48:38 +0000
committerxue <>2007-10-06 21:48:38 +0000
commite4320cab263a45f8920599d5c919230309e7284c (patch)
treeeaa96c8cb2e5470897eade01d6caf9f49a5f9438 /framework
parentf8131d4a0169c65eb148437827726624fca1a7f6 (diff)
Added TDbCommand.queryColumn()
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/TDbCommand.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/framework/Data/TDbCommand.php b/framework/Data/TDbCommand.php
index f5d7d647..b4bd9dd4 100644
--- a/framework/Data/TDbCommand.php
+++ b/framework/Data/TDbCommand.php
@@ -283,6 +283,23 @@ class TDbCommand extends TComponent
throw new TDbException('dbcommand_query_failed',$e->getMessage(),$this->getDebugStatementText());
}
}
+
+ /**
+ * Executes the SQL statement and returns the first column of the result.
+ * This is a convenient method of {@link query} when only the first column of data is needed.
+ * Note, the column returned will contain the first element in each row of result.
+ * @return array the first column of the query result. Empty array if no result.
+ * @throws TDbException execution failed
+ * @since 3.1.2
+ */
+ public function queryColumn()
+ {
+ $rows=$this->query()->readAll();
+ $column=array();
+ foreach($rows as $row)
+ $column[]=current($row);
+ return $column;
+ }
}
?> \ No newline at end of file