Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: External database enrolment.

Talk:External database enrolment

From MoodleDocs

Dear Americans, not everyone spells the word enrolment the way you do ;-) I just rolled back some edits.--Tim Hunt 06:21, 26 March 2009 (UTC)

Example External Enrollment

In this example using a MySQL database pulling information from a Powerschool server. A Java Script pulls the following information on a cron job and places it into a Mysql database.

The External Database has 2 tables courses and enrollments Courses Table has the following Fields:

  • id - Unique Key that autoincrements
  • fullname - The full name of the course
  • shortname - the shortname of the course
  • idnumber - a unique id number for the course in this case the same as the shortname
  • category - the category number (same as in the Moodle database)

The enrollments table has the following fields

  • id - a unique key that autoincrements and is unused in external enrollments
  • student_number - a unique number that matches the idnumber field in moodle_users table
  • courseNumber - a number that matches the course's idnumber
  • role - either teacher or student

In the: /admin/settings.php?section=enrolsettingsdatabase page

  • Database Driver - mysqli
  • Database host - localhost (the external database is on the same server)
  • Database User - a User with access to the database and the ability to run SET NAMES 'utf8'
  • Database password - the database user's password
  • Database Name - moodlesync in this example
  • Database Encoding - utf-8
  • Database Setup command - SET NAMES 'utf8'
  • Local Course field - idnumber
  • Local user field - idnumber
  • local role field - shortname
  • Remote User Enrollment Table - enrolments
  • Remote course field - courseNumber
  • Remote user field - student_number
  • Remote role field - role
  • Default Role - Student
  • External unenrol action - Keep User Enrolled (just in case so grades are not purged).
  • Remote new courses - courses
  • New course full name - fullname
  • New course short name - shortname
  • New course ID number field - idnumber
  • New course category id field - category
  • Default new course category - Miscellaneous


This is a setup that has been tested to work in Moodle 2.0 using the External Database Enrolment. It also can work with the syntonization script run with the command: sudo /PATHTOPHP/php /PATHTOMOODLE/enrol/database/cli/sync.php