Databases: database retrievel

Databases: database retrievel

av preetam thakur -
Antall svar: 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
Gjennomsnittlig vurdering: -
Som svar til preetam thakur

Re: Databases: database retrievel

av 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
Som svar til Just H

Re: Databases: database retrievel

av 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
Som svar til vijesh g

Re: Databases: database retrievel

av 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.
Som svar til Jan Dierckx

Pblm again -please help-database retrievel

av 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
Som svar til vijesh g

Re: Pblm again -please help-database retrievel

av 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