Databases: database retrievel

Databases: database retrievel

napisao/la preetam thakur -
Broj odgovora: 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
U odgovoru na preetam thakur

Re: Databases: database retrievel

napisao/la 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
U odgovoru na Just H

Re: Databases: database retrievel

napisao/la 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
U odgovoru na vijesh g

Re: Databases: database retrievel

napisao/la 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.
U odgovoru na Jan Dierckx

Pblm again -please help-database retrievel

napisao/la 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
U odgovoru na vijesh g

Re: Pblm again -please help-database retrievel

napisao/la 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