Commit be550b4e authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1698978: get_records_*_assoc functions fail on one field

If we are trying to fetch only 1 field then we can't use the
$rs->GetAssoc() function as that expects 2 fields minimum.

We can get around this in lib/dml.php by creating our own assoc return


Change-Id: I6a4a9beadc4abeebc5d73bac6128d56f46ce4676
Signed-off-by: Robert Lyon's avatarRobert Lyon <>
parent 0b30a77a
......@@ -556,6 +556,20 @@ function recordset_to_array(ADORecordSet $rs) {
* @access private
function recordset_to_assoc(ADORecordSet $rs) {
if ($rs->NumCols() < 2) {
$colname = $rs->FetchField(0)->name;
$records = $rs->GetAll();
if (empty($records)) {
return false;
$objects = [];
foreach ($records as $val) {
$objects[(string) $val[$colname]] = (object) $val;
return $objects;
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment