Knowing a user's Moodle ID

Knowing a user's Moodle ID

by James Valentine -
Number of replies: 2
Dear all,

I understand that the enrolment DB contains two fields: the Moodle user ID and the Course ID. I know the course ID, because I set that. As I'm creating users and authenticating them with a different external DB, I don't know the Moodle IDs of my users.

My problem is this: how can I put their IDs into the enrolment table without knowing them? How can I fetch this information? Or will Moodle use my own IDs, and must I code that into my external system?

Many thanks for your thoughts.
J.
Average of ratings: -
In reply to James Valentine

Re: Knowing a user's Moodle ID

by Jonathan Moore -
Typically you would set the Moodle user ID, to ID Number which is intended to be a value specified by you as part of the external integration (ie a foreign key).


In reply to Jonathan Moore

Re: Knowing a user's Moodle ID

by James Valentine -
As I'm leaving Moodle to work out the IDs (with DB authentication), I'm solving the problem by running a SELECT DISCRETE joining query across the database of my external system and the Moodle DB:

 SELECT moodledb.user.idnumber, ext_enrolments.courseid
 FROM ext_enrolments, moodledb.user
 WHERE moodledb.user.username = ext_enrolments.username;

That gives me result rows that include the Moodle ID, keyed on the username (which I know). I then squirt these into a csv file.

Thanks for your help.
J.