]> git.mjollnir.org Git - moodle.git/commitdiff
Changes to get a more reliable insert ID for any table
authormoodler <moodler>
Sun, 22 Dec 2002 06:33:30 +0000 (06:33 +0000)
committermoodler <moodler>
Sun, 22 Dec 2002 06:33:30 +0000 (06:33 +0000)
lib/datalib.php

index 28e582447224072ae9fc17ac67de3d8cb0de72b2..aed6ec1480d8b498d8d8f96a4f8be63b841646db 100644 (file)
@@ -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;
     }