yii\db\mssql\PDO::lastInsertId PHP Method

lastInsertId() public method

Returns value of the last inserted ID.
public lastInsertId ( string | null $sequence = null ) : integer
$sequence string | null the sequence name. Defaults to null.
return integer last inserted ID value.
    public function lastInsertId($sequence = null)
    {
        return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn();
    }