diff options
-rw-r--r-- | lib/private/DB/Connection.php | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 93d493507af..dd55e40fab8 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -529,12 +529,13 @@ class Connection extends PrimaryReadReplicaConnection { * @throws Exception */ public function realLastInsertId($seqName = null): int { - if ($this->lastInsertId !== 0) { - $lastInsertId = $this->lastInsertId; - $this->lastInsertId = 0; - return $lastInsertId; + $previousLastInsertId = $this->lastInsertId; + $lastInsertId = (int)parent::lastInsertId($seqName); + if ($lastInsertId === 0 && $previousLastInsertId !== 0) { + $lastInsertId = $previousLastInsertId; } - return (int)parent::lastInsertId($seqName); + $this->lastInsertId = 0; + return $lastInsertId; } /** |