Hello,
I gave it some research, and have tested out the next things.
First, as says Eric Mueller, the documentation of adodb is quiet clear, esp. the tutorial.
quote:
Retrieving the Data
while (!$result->EOF) {
for ($i=0, $max=$result->FieldCount(); $i < $max; $i++)
print $result->fields[$i].' ';
$result->MoveNext();
print "<br>\n";
}The paradigm for getting the data is that it's like reading a file. For every line, we check first whether we have reached the end-of-file (EOF). While not end-of-file, loop through each field in the row. Then move to the next line (MoveNext) and repeat.
The $result->fields[] array is generated by the PHP database extension. Some database extensions do not index the array by field name. To force indexing by name - that is associative arrays - use the $ADODB_FETCH_MODE global variable.
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs1 = $db->Execute('select * from table');
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs2 = $db->Execute('select * from table');
print_r($rs1->fields); // shows array([0]=>'v0',[1] =>'v1')
print_r($rs2->fields); // shows array(['col1']=>'v0',['col2'] =>'v1')
As you can see in the above example, both recordsets store and use different fetch modes based on the $ADODB_FETCH_MODE setting when the recordset was created by Execute().
unquote (sorry for the formatting
as to your example, you had to correct the sql-statement (1), then (2) the following would work correctly:
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$result = $db->Execute("SELECT avg(number) as average from table");
print $result->fields['average'];
seems it's not being any shorter than this.