Databases: database retrievel

Databases: database retrievel

von preetam thakur -
Anzahl Antworten: 5
I am new to  moodle.I would like to fetch some values from the database.Please specify what are the files i needed and the functions.

Regards

Preetham
Als Antwort auf preetam thakur

Re: Databases: database retrievel

von Just H -
Hi Preetam

Although I can't help you as mysql is not my thing, I also doubt anyone can unless you give them a bit more information e.g. what information are you wanting to fetch?

Harry
Als Antwort auf Just H

Re: Databases: database retrievel

von vijesh g -
Hai smith

i want to fetch some value from one table.(any table).But i couldnt find out how they wrote code for this .Can you help me

regards

Preetham
Als Antwort auf vijesh g

Re: Databases: database retrievel

von Jan Dierckx -
You can use the Moodle database functions from lib/datalib.php...

Example:

get_record('onetable','field',value);

will return the first record from a table where field = value.
Als Antwort auf Jan Dierckx

Pblm again -please help-database retrievel

von vijesh g -
Hai jan
i tried like this

get_record('mdl_user','username',1);

where mdl_user is a table in moodle database

but it was not printing anything.

Can u help me i need it immdtly ... please
Als Antwort auf vijesh g

Re: Pblm again -please help-database retrievel

von Jan Dierckx -
That's because '1' is an unlikely username. If you want to look up by userid, use something like get_record('mdl_user','id',1); or (better still) use some of the builtin functions for getting userdata.

Try experimenting with different functions. Use phpmyadmin to discover which fields are used in Moodle's database. It takes sometime to find out what different functions are for.
documentation: http://docs.moodle.org/en/Developer_documentation#Resources_and_tools