From 5658dfc9289060f329fd7c3f0590053871a4bd14 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sun, 14 Mar 2021 17:46:48 +0100 Subject: Add loop to get the last result Server may return more than one row if triggers are involved (see #41). --- drivers/adodb-mssqlnative.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/adodb-mssqlnative.inc.php') diff --git a/drivers/adodb-mssqlnative.inc.php b/drivers/adodb-mssqlnative.inc.php index 7674a154..3b9d905a 100644 --- a/drivers/adodb-mssqlnative.inc.php +++ b/drivers/adodb-mssqlnative.inc.php @@ -648,8 +648,11 @@ class ADODB_mssqlnative extends ADOConnection { if (!$rez) { $rez = false; } elseif ($retrieveLastInsertID) { - // Get the inserted id from the 2nd result - if (sqlsrv_next_result($rez) && sqlsrv_fetch($rez)) { + // Get the inserted id from the last result + // Note: loop is required as server may return more than one row, + // e.g. if triggers are involved (see #41) + while (sqlsrv_next_result($rez)) { + sqlsrv_fetch($rez); $this->lastInsID = sqlsrv_get_field($rez, 0, SQLSRV_PHPTYPE_INT); } } -- cgit v1.3