]> git.mjollnir.org Git - moodle.git/commitdiff
Adding back the first column in the recordset, that is out after GetAssoc(),
authorstronk7 <stronk7>
Sat, 26 Aug 2006 00:08:11 +0000 (00:08 +0000)
committerstronk7 <stronk7>
Sat, 26 Aug 2006 00:08:11 +0000 (00:08 +0000)
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.

lib/dmllib.php

index 5cb8f2673ab03e7c79e5f69398d092e51030b121..a78ecd2df7c051ed4be7427f227f52ff1ee37160 100644 (file)
@@ -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 {