From 1523be781faefd2e6d3c1e516845166c2637f2a2 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 22 Dec 2002 06:33:30 +0000 Subject: [PATCH] Changes to get a more reliable insert ID for any table --- lib/datalib.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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; } -- 2.39.5