Add users from another database

Add users from another database

by Elie Reformed -
Number of replies: 10

Hi all, so I wanna add users from a database of another web application to my moodle instance, so I need to do some sort of mapping between the fields of the user table... So what are the api's that I need to work with? any tips?

Average of ratings: -
In reply to Elie Reformed

Re: Add users from another database

by Luis de Vasconcelos -

Is this a once-off migration that you are doing, or will you need to do it regularly?

If it's a once-off job, try exporting the user details from your other web application into a Moodle compatible .csv file. See: https://docs.moodle.org/31/en/Upload_users#Valid_upload_file_for_testing for details.

Then you can import that .csv file into Moodle to create the users in Moodle.

In reply to Luis de Vasconcelos

Re: Add users from another database

by Elie Reformed -

Ty for your response but It's not a once-off migration. sad

In reply to Elie Reformed

Re: Add users from another database

by Luis de Vasconcelos -

So you want to "synchronise" your Moodle database with an external database?

Try this: https://docs.moodle.org/31/en/External_database_authentication

If the users in your external database aren't in Moodle then they will be created in Moodle. Is that what you want?

Average of ratings: Useful (1)
In reply to Luis de Vasconcelos

Re: Add users from another database

by Elie Reformed -
"So you want to "synchronise" your Moodle database with an external database?"

Yes that's exactly what I want. I will see the link that you suggested. ty smile

In reply to Luis de Vasconcelos

Re: Add users from another database

by Elie Reformed -

Hmm , when choosing the external database, I can't find MariaDB? What can I do?

edit: I'll try the Mysql option  and see how it goes. (because MariaDB is based on MySQL ? idk)

In reply to Luis de Vasconcelos

Re: Add users from another database

by Elie Reformed -
hmm It didn't work:


Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\inetpub\wwwroot\moodle\lib\adodb\drivers\adodb-mysql.inc.php on line 462


Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\inetpub\wwwroot\moodle\lib\adodb\drivers\adodb-mysql.inc.php on line 462

127.0.0.1: Access denied for user 'root'@'localhost' (using password: YES)

Cannot connect the database.

In reply to Elie Reformed

Re: Add users from another database

by Elie Reformed -
What a stupid mistake... I was giving the wrong password of the root... dead

Works fine now.

In reply to Elie Reformed

Re: Add users from another database

by Perry Way -

You might have to do some programming if your case is elaborate like ours is. We have a student/school management system that is our back office app. Many conditions occur that will cause a student to be enrolled or unenrolled into particular courses, plus also we have those issues of when a student is suspended or deleted, for variety of reasons. So I had to write a series of programs to do everything including the exporting of student data from our back office application to a CSV, then read that CSV in with the importing program and then to create accounts if not already created, enroll/unenroll, suspend or unsuspend as the case might be.

If you want to go down that road to gain the benefits of controlled enrollments and suspensions, etc, let me know and I'll provide some more pertinent information that will help you get that ball rolling.

In reply to Perry Way

Re: Add users from another database

by Elie Reformed -

Yeah Perry, it would be awesome if you can give us some information. ty smile

In reply to Perry Way

Re: Add users from another database

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

We handled a similar situation a little differently - but it would totally depend on the back-end of your SIS.

In our case (using an SIS called Quercus, which is based on an Oracle database), our Admin team created a report in the back-end that takes all such considerations into account (or whichever ones are relevant to our situation - campus, suspensions, payments, etc). That report then gives a table in the back-end database and I simply use Moodle's external database for automatic course creation and enrolment.