picodb(mssql): fix implementation of getLastId() on MSSQL

This commit is contained in:
Joe Nahmias 2022-07-11 08:44:28 -04:00 committed by Frédéric Guillot
parent 37bc859df5
commit 66d55e5be0
1 changed files with 9 additions and 1 deletions

View File

@ -136,7 +136,15 @@ class Mssql extends Base
*/
public function getLastId()
{
return $this->pdo->lastInsertId();
try {
$rq = $this->pdo->prepare('SELECT @@IDENTITY');
$rq->execute();
return $rq->fetchColumn();
}
catch (PDOException $e) {
return 0;
}
}
/**