General developer forum

How to access Database Activity programmatically

 
Picture of John Kouraklis
How to access Database Activity programmatically
 
Hi everyone,

I am trying to figure out how to access the database activity programmatically.

I can't seem to be able to fin dhow Database activity is stored in Moodle. Whenever I search for it, I get the general database scheme. 

Does anyone have a link? Also an code example how to access fields would be great.

Thanks

John

 
Average of ratings: -
Picture of AL Rachels
Re: How to access Database Activity programmatically
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi John,

Typically, any Moodle plugin database table uses its name prefixed with mdl_. In this case the main database activity table is, mdl_data. It also uses, mdl_data_content, mdl_data_fields, and mdl_data_records.

If you visit the Development tab at the top of this page, and then go to Core APis you will see Data manipulation API. There are many examples there.

Warning: It seems to me you plan on trying to directly manipulate the the data in the activity. If so, please try things on a development Moodle site and not on a production site.

 
Average of ratings: Useful (1)
Picture of John Kouraklis
Re: How to access Database Activity programmatically
 

Hi Al,

thanks for the suggestions and clarifications.

I am indeed planning to hit the database directly. So, I am writing a desktop app and many times the users keeps some stuff in a Database activity on Moodle. 

So, I was thinking to provide access to that activity directly from my app but after your comment and what I read I feel it is a bit risky and complicated.

Maybe I will pass.

What do you think?

 
Average of ratings: -
Picture of AL Rachels
Re: How to access Database Activity programmatically
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi John,

Frankly, I would not. I think it is too much of a risk. Even using the built in database API while working on adding GDPR code to Hot Question a couple of weeks ago, I accidentally trashed my development Moodle, due to a misplace comma. Luckily, I had a recent backup.

 
Average of ratings: Useful (1)
Picture of John Kouraklis
Re: How to access Database Activity programmatically
 

Hi Al,

yeah I though so; sounds risky to mess with tables and records. After all, in a real and commercial environment I can't be sure that I will be able to connect to the database directly.

Thanks for the help.


 
Average of ratings: -