update moodle table record

update moodle table record

by Baiju Sharma -
Number of replies: 1

I have a task where I have to update table row (duedate). Table name is mdl_competency_plan.

I am implementing a scheduled task which will run automatically and update user competency plan "duedate" row.

I have "userid" and "name" of the row to be updated.

Below is my code.It is not updating the row.

 $DATA = $DB->get_recordset_sql ("Select userid,name,duedate from vw_duedate_autosetuser");      

         $setduedate= strtotime('duedate');         

$DB->execute("UPDATE {competency_plan} SET duedate= '{$setduedate}' WHERE userid = '{$userid}' AND name= '{$name}'");

var_dump gives me below record.

 array(3) {

    ["userid"]=>

    string(4) "3966"

    ["name"]=>

    string(15) "Learning Plan 1"

    ["duedate"]=>

    string(19) "2019-04-14 07:15:10"

  }




Average of ratings: -
In reply to Baiju Sharma

Re: update moodle table record

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

I highly recommend you read the Moodle data manipulation API to learn how to use Moodle's database functions, as well as look at sample code in the Moodle codebase.

As written, your code is not using that correctly.