Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-5877

recordset_to_array returns false if column count is 1

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7
    • Fix Version/s: 1.7
    • Labels:
      None
    • Environment:
      All
    • Database:
      Any
    • Affected Branches:
      MOODLE_17_STABLE
    • Fixed Branches:
      MOODLE_17_STABLE

      Description

      File:

      datalib.php

      Description:

      recordset_to_array() returns false if you try select one column from the database. This causes get_records() to fail if you pass in one field name.

      Example:

      $pagenames = get_records('wiki_pages', 'wiki', $entry->id, '', 'pagename');

      returns nothing.

      Fix:

      function recordset_to_array($rs) {

      if ($rs && $rs->RecordCount() > 0) {

      if ($records = $rs->GetAssoc(true)) {

      foreach ($records as $key => $record)

      { $objects[$key] = (object) $record; }

      return $objects;

      } elseif ($rs->_numOfFields == 1) {

      $records = $rs->GetRows();

      if (count($records) > 0)

      { return $records; }

      else

      { return false; }

      } else

      { return false; }

      } else

      { return false; }

      }

        Attachments

          Activity

            People

            Assignee:
            dougiamas Martin Dougiamas
            Reporter:
            imported Imported
            Tester:
            Nobody
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              7/Nov/06