I had a similar issue just now. (Moodle 2.3.2 server that is running smoothly for along time)
I have no idea how it started ???
Since very few users used the system between the last DB backup and the current DB state...
Eventually, I reverted to a backup DB from a few hours before this phenomena started and all works just fine.
btw,
I was running the problematic SQL query that returned this error "select * from mdl_course where category >=0;" (manually) and it works fine (got 1600+ courses) so i have no idea why
function get_site() {
global $SITE, $DB;
if (!empty($SITE->id)) { // We already have a global to use, so return that
return $SITE;
}
if ($course = $DB->get_record('course', array('category'=>0))) {
return $course;
} else {
// course table exists, but the site is not there,
// unfortunately there is no automatic way to recover
throw new moodle_exception('nosite', 'error');
}
}
does not work and throws an exception