0

I'm trying to a create new activity in Moodle it created successfully but I can't add a new instance in my dB in my lib.php

function activity_add_instance($data){
    global $DB;

    $data->timecreated = time();
    $data->timemodified = time();
    $cmid = $data->coursemodule;

    $data->id = $DB->insert_record('testnew', $data);
     
    $DB->set_field('course_modules', 'instance', $data->id, ['id' => $cmid]);

    // Extra fields required in grade related functions.
    $data->cmid = $data->coursemodule;
    return $data->id;
}

no new data is found in table testnew so this error appeared :

Error reading from database
Aya Ashraf
  • 13
  • 3

1 Answers1

0

You need to create the table during the install. Assuming testnew is the activity name, the table structures should be in

/mod/testnew/db/install.xml

You can create the file via Site administration > Development > XMLDB editor

https://docs.moodle.org/dev/Activity_modules#install.xml

Russell England
  • 9,436
  • 1
  • 27
  • 41