From: moodler Date: Sun, 22 Dec 2002 06:33:30 +0000 (+0000) Subject: Changes to get a more reliable insert ID for any table X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1523be781faefd2e6d3c1e516845166c2637f2a2;p=moodle.git Changes to get a more reliable insert ID for any table --- diff --git a/lib/datalib.php b/lib/datalib.php index 28e5824472..aed6ec1480 100644 --- a/lib/datalib.php +++ b/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; }