array getAssoc(
[boolean
$scalar = false])
|
|
Fetch the entire result set of a query and return it as an associative array using the first column as the key.
Note: column names are not preserved when using this function.
- For example, if the table 'mytable' contains:
-
- ID TEXT DATE
- --------------------------------
- 1 'one' 944679408
- 2 'two' 944679408
- 3 'three' 944679408
-
- $q = new Query("SELECT id, text FROM mytable")
- $q->getAssoc() returns:
- array(
- '1' => array('one'),
- '2' => array('two'),
- '3' => array('three'),
- )
-
- ... or call $q->getAssoc($scalar=true) to avoid wrapping results in an array (only
- applies if only 2 cols are returned):
- array(
- '1' => 'one',
- '2' => 'two',
- '3' => 'three',
- )
Keep in mind that database functions in PHP usually return string values for results regardless of the database's internal type.
Tags:
Parameters:
Gets a QueryDataSet representing results of this query.
The QueryDataSet that is returned will be ready to use (records will already have been fetched). Currently only QueryDataSets are returned, so you will not be able to manipulate (update/delete/insert) Record objects in returned DataSet.
- $q = new Query("SELECT * FROM author");
- $q->setLimit(10);
- $qds = $q->getDataSet();
- foreach($q->getDataSet() as $rec) {
- $rec->getValue("name");
- }
Tags: