Moodle Database API - Inserting Records - Moodle 2.9

Moodle Database API - Inserting Records - Moodle 2.9

by Dave Emsley -
Number of replies: 2

Hi there,

A bit confused with     $lastinsertid = $DB->insert_record($table , $record, false);

as the value of $lastinsertid always returns 1 (true?) rather than an actual value of the "lastinsertid" as I would expect.

Is this correct?  Do I now need to do a search to get the record id? 

Seems a bit heavy on the db.


Cheers

Dave

Average of ratings: -
In reply to Dave Emsley

Re: Moodle Database API - Inserting Records - Moodle 2.9

by Paul Holden -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Whatever you've copy/pasted that from is setting the third function argument ($returnid) to false, so you're not going to get the inserted record ID as a return value wink

See function docblock in your IDE, or here:

* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.

Average of ratings: Useful (1)