Donut Team is a labor of love, built and maintained by a small group of passionate developers. We invest our own time and resources to offer our tools, mods, and web services completely free of charge.

We don't run ads, and we will never sell your data - period.

If you've enjoyed anything we've created, please consider supporting our work with a one-time or monthly donation via our Ko-fi page . Every contribution helps us continue building great experiences for the community.

Dismiss
  • Modding Tools
  • Simpsons Hit & Run Multiplayer Server
  • Lua API Reference
  • DB Functions

DB.LastInsertId

Available since Version 1.0.

Returns the ID of the last row that was inserted into the database.

Syntax

DB.LastInsertId()

Arguments

No arguments.

Return Values

(number): The ID of the last row that was inserted into the database. If no rows have been inserted, this will return 0.

Examples

DB.Execute([[
    INSERT INTO users (username, password_hash, operator)
    VALUES (@username, @password_hash, 1);
]],
{
    username = "maz_likes_eggs",
    password_hash = Cryptography.SHA256("super_secure_password")
})

local lastId = DB.LastInsertId()
print(lastId) -- Outputs: 1 (example output, will vary based on the actual last inserted ID)