Moodle insert_record not inserting all data, when manually create a column of a table

$DB->insert_record([table], $obj) not inserting all data from $obj

Solution:

Site administration -> Development -> Purge all caches

Important Note:

Assuming you used the standard Moodle upgrade functions to add extra fields to the database, you shouldn’t need to clear the cache. This should only be needed if you manually added fields to the database (which aside from the caching issue, is also a bad idea if you ever want to set up a clean development server alongside your production server).

So, Don’t do it. If you need extra information, put them into a new table in your own plugin (with the correct name prefix) and refer to the original table with 1:1 relationship (which is a special case of 1:N). When selecting data, simply JOIN the core and your tables.

Standard solution :

the cache should not be the issue if using the standard moodle DB class.  I’ve used code like this:


$dataObj = new stdClass();
$dataObj->id = $ueid;
$unixconverted = strtotime($edate);
$unixconvertedadjusted = strtotime('+1 day', $unixconverted);
$dataObj->timecreated = $unixconvertedadjusted;
$table = 'user_extrafields';

$DB->update_record($table, $dataObj);

Create you object from the class, ensure you have a unique id for the ->id value for the required  $dataObj->id, in my case I converted a string to time and then added a day to it and stored that in a the user_extrafields table., no need to use mdl_ prefix when using the DB class.

Pass the table name and the dataObj variables to the update_record method of the $DB class.

Cheers

Source: Moodle Forum