From: martinlanghoff Date: Wed, 20 Sep 2006 11:26:47 +0000 (+0000) Subject: dmlib: changed array access to keyed instead of ordinal. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d7e901c66989c19421c8431f920ccda7edd9d5b0;p=moodle.git dmlib: changed array access to keyed instead of ordinal. This supports the move to ADODB_FETCH_ASSOC instead of ADODB_FETCH_BOTH. see: http://docs.moodle.org/en/XMLDB_Problems#ADOdb_fetch_mode_.28ASSOC.2C_NUM_and_BOTH.29 Author: Luke Hudson --- diff --git a/lib/dmllib.php b/lib/dmllib.php index e1589468a5..0fd9f1b179 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -334,7 +334,7 @@ function count_records_sql($sql) { $rs = get_recordset_sql($sql); if ($rs) { - return $rs->fields[0]; + return reset($rs->fields); } else { return 0; } @@ -747,8 +747,11 @@ function get_records_sql($sql, $limitfrom='', $limitnum='') { */ function recordset_to_menu($rs) { if ($rs && $rs->RecordCount() > 0) { + $keys = array_keys($rs->fields); + $key0=$keys[0]; + $key1=$keys[1]; while (!$rs->EOF) { - $menu[$rs->fields[0]] = $rs->fields[1]; + $menu[$rs->fields[$key0]] = $rs->fields[$key1]; $rs->MoveNext(); } return $menu; @@ -857,7 +860,7 @@ function get_field_sql($sql) { $rs = get_recordset_sql($sql); if ($rs && $rs->RecordCount() == 1) { - return $rs->fields[0]; + return reset($rs->fields); } else { return false; } @@ -890,9 +893,11 @@ function get_fieldset_sql($sql) { } if ( $rs->RecordCount() > 0 ) { + $keys = array_keys($rs->fields); + $key0 = $keys[0]; $results = array(); while (!$rs->EOF) { - array_push($results, $rs->fields[0]); + array_push($results, $rs->fields[$key0]); $rs->MoveNext(); } return $results; @@ -1134,7 +1139,7 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') { if ( ($rs = $db->Execute('SELECT '. $primarykey .' FROM '. $CFG->prefix . $table .' WHERE oid = '. $id)) && ($rs->RecordCount() == 1) ) { trigger_error("Retrieved $primarykey from oid on table $table because we could not find the sequence."); - return (integer)$rs->fields[0]; + return (integer)reset($rs->fields); } trigger_error('Failed to retrieve primary key after insert: SELECT '. $primarykey . ' FROM '. $CFG->prefix . $table .' WHERE oid = '. $id);