Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changes to get a more reliable insert ID for any table

  • Loading branch information...
commit 1523be781faefd2e6d3c1e516845166c2637f2a2 1 parent d26d7ed
moodler authored
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/datalib.php
View
15 lib/datalib.php
@@ -411,12 +411,19 @@ function insert_record($table, $dataobject, $returnid=true) {
}
if ($returnid) {
- // Pull it out again to find the id. This is the most cross-platform method.
+ if ($db->hasInsertID) {
+ return $db->Insert_ID(); // ADOdb has stored the ID for us
+ }
+
+ // Try to pull the record out again to find the id. This is the most cross-platform method.
if ($rs = $db->Execute("SELECT id FROM $CFG->prefix$table WHERE $select")) {
- return $rs->fields[0];
- } else {
- return false;
+ if ($rs->RecordCount() == 1) {
+ return $rs->fields[0];
+ }
}
+
+ return false;
+
} else {
return true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.