From: stronk7 Date: Sat, 26 Aug 2006 00:08:11 +0000 (+0000) Subject: Adding back the first column in the recordset, that is out after GetAssoc(), X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7e8f922047e5c8b8615b815dd7ac947b539bc3e5;p=moodle.git Adding back the first column in the recordset, that is out after GetAssoc(), in order to: - Don't get our first named column under some drivers. - Be able to migrate to ADODB_FETCH_ASSOC soon. For more info, http://docs.moodle.org/en/XMLDB_Problems, in the ADOdb fetch mode (ASSOC, NUM and BOTH) section. --- diff --git a/lib/dmllib.php b/lib/dmllib.php index 5cb8f2673a..a78ecd2df7 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -629,9 +629,15 @@ function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) { */ function recordset_to_array($rs) { if ($rs && $rs->RecordCount() > 0) { + /// First of all, we are going to get the name of the first column + /// to introduce it back after transforming the recordset to assoc array + /// See http://docs.moodle.org/en/XMLDB_Problems, fetch mode problem. + $firstcolumn = $rs->FetchField(0); + /// Get the whole associative array if ($records = $rs->GetAssoc(true)) { foreach ($records as $key => $record) { - $objects[$key] = (object) $record; + $record[$firstcolumn->name] = $key;/// Re-add the assoc field + $objects[$key] = (object) $record; /// To object } return $objects; } else {