protected static function get_records($whereclause, $params) {
        global $DB;
        // Retrieve from DB only the fields that need to be stored in cache.
        $fields = array_keys(array_filter(self::$coursecatfields));
        $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
        $sql = "SELECT cc.". join(',cc.', $fields). ", $ctxselect
                FROM {course_categories} cc
                JOIN {context} ctx ON cc.id = ctx.instanceid AND ctx.contextlevel = :contextcoursecat
                WHERE ". $whereclause." ORDER BY cc.sortorder";
        return $DB->get_records_sql($sql,
                array('contextcoursecat' => CONTEXT_COURSECAT) + $params);
    }
protected static function get_records($whereclause, $params) {
        global $DB;
        // Retrieve from DB only the fields that need to be stored in cache.
        $fields = array_keys(array_filter(self::$coursecatfields));
        $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
        $sql = "SELECT cc.". join(',cc.', $fields). ", $ctxselect
                FROM {course_categories} cc
                JOIN {context} ctx ON cc.id = ctx.instanceid AND ctx.contextlevel = :contextcoursecat
                WHERE ". $whereclause." ORDER BY cc.sortorder";
        return $DB->get_records_sql($sql,
                array('contextcoursecat' => CONTEXT_COURSECAT) + $params);
    }
protected static function get_records ( $ whereclause , $ params ) { global $ DB ; // Retrieve from DB only the fields that need to be stored in cache. $ fields = array_keys ( array_filter ( self :: $ coursecatfields ) ) ; $ ctxselect = context_helper :: get_preload_record_columns_sql ( 'ctx' ) ; $ sql = "SELECT cc." . join ( ',cc.' , $ fields ) . ", $ctxselect
                FROM {course_categories} cc
                JOIN {context} ctx ON cc.id = ctx.instanceid AND ctx.contextlevel = :contextcoursecat
                WHERE " . $ whereclause . " ORDER BY cc.sortorder" ; return $ DB -> get_records_sql ( $ sql , array ( 'contextcoursecat' => CONTEXT_COURSECAT ) + $ params ) ; }
Retrieves number of records from course_categories table

Only cached fields are retrieved. Records are ready for preloading context

@param string $whereclause
@param array $params
@return array array of stdClass objects
Retrieves number of records from course_categories table