Tzahi,
The $course and $DB variables are objects, so to examine them you should be using things like
echo $course->id;
print_r ($course);
print_r ($DB);
var_dump ($course);
var_dump ($DB);
Your $DB->get_record_sql statement should read
$DB->get_record_sql ($query);
You may want to take a look at where similar things are used in the Moodle codebase in order to get an idea how to do the same.
-- Muyi