fetch moodle data in another php file

fetch moodle data in another php file

rupz jindal -
回帖数:5

HI all,


I am facing a issue. I have to fetch data from moodle without loggin to it. I have to create a seperate php which is not a part of moodle directory. This file will fetch course from moodle database and display it. Please help me to sought it out.


回复rupz jindal

Re: fetch moodle data in another php file

Howard Miller -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

It really depends on what 'data' you want to fetch?

回复rupz jindal

Re: fetch moodle data in another php file

PLAYlive Admin -
Can you not do a SQL SELECT statement to get the page content you need without even touching moodle?
回复PLAYlive Admin

Re: fetch moodle data in another php file

Colin Fraser -
Documentation writers的头像 Testers的头像

As long as you have the correct access to the database, you could. The Moodle database is a database, like any other, it should be a black box as it is only the interface, the GUI, that defines Moodle. 

Be interesting to see if this works, though, trying to structure data via a different data extraction tool can be a serious headache. If the data is encrypted, then you will need the correct encryption key. From discussions about Moodle v2.0, long ago, so I am relying on memory here, there was a lot of discussion about the way in which data values would be encrypted seriously enhancing the internal security of the database.  Also, I seem vaguely to recall that you will need to get the correct sesskey value as well, without it, you may not get anything useful. Having said that, phpMyAdmin and similar tools will access the database and produce the majority of data. It is not always in a useful form, but the GUI does allow you to construct SQL statements to extract useful data for reports and such.  

 

回复rupz jindal

Re: fetch moodle data in another php file

Mark Sharp -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像

If the file is on the same server as Moodle then you can exploit Moodle's DB abstraction by including the config.php file. There are a few functions that don't check for capabilities, but where they do perhaps you'll need to write your own query.

An alternative way of doing it, and the only way of doing it if you're on a different server, is to use web services. It takes a bit of setting up, but you can query Moodle using REST. Moodle will return an array with which you can do what you like. https://docs.moodle.org/dev/Web_services

Either way, you'd need to get your hands dirty with some PHP coding. Unfortunately, there's no shortcut.