Databases: How to update/insert value in DB

Databases: How to update/insert value in DB

by leena gour -
Number of replies: 4
I have added a new field in db mdl_resource and similarly i have added a new radio button for the field on form (add resource for course),now where to write code to insert value of this new field to db.
Is there any generic method to update databases or at form level only i have to write code to insert such fields and how??????????

Thanks

Average of ratings: -
In reply to leena gour

Re: Databases: How to update/insert value in DB

by Luis de Vasconcelos -

Without more information it's very difficult to say where you need to add the code.

Also, I'd be VERY careful when adding new fields to the database. It could cause problems in the future when you need to upgrade Moodle.

In reply to Luis de Vasconcelos

Re: Databases: How to update/insert value in DB

by Dave Perry -
Picture of Testers
We discussed this at the Yorkshire/Humberside Moodle User Group a couple of months ago - as long as you document the changes you made and where you should be ok for upgrades. And make sure you're backing up the column of database you've added in SEPARATELY to the main database backups for importing to an upgrade.
In reply to Luis de Vasconcelos

Re: Databases: How to update/insert value in DB

by leena gour -
Thanks for response.

Actually I have added a field in moodle/mod/resource/mod_form.php and respective field in DB mdl_resource, but where to write query to insert value of this new field to DB. May be i have added field in wroung place or i don't know how to relate field with DB in moodle.

leena
In reply to leena gour

Re: Databases: How to update/insert value in DB

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think that if the column has the same name as the form field, the insert will happen automatically.