DbQuery
dbQuery
Starts an asynchronous prepared SQL query.
Syntax
DatabaseQuery dbQuery([function callback, table callbackArguments,] DatabaseConnection connection, string statement, ...)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
callback |
function |
no | Optional function called when the result becomes available. |
callbackArguments |
table |
no | Optional values passed to the callback after the query handle. |
connection |
DatabaseConnection |
yes | The connection used to execute the query. |
statement |
string |
yes | SQL containing ? value placeholders.
|
... |
nil/bool/number/string |
no | Values bound to the statement placeholders. |
Returns
Returns a DatabaseQuery handle on success, or false if the query could not be queued.
Examples
Load one player asynchronously:
dbQuery(function(query)
local rows = dbPoll(query, 0)
if rows then
for _, row in ipairs(rows) do
print(row.name, row.level)
end
end
end, {}, db, "SELECT name, level FROM players WHERE id = ?", playerId)
Notes
- Available only in server-side resource scripts.
- Prefer the callback form so that the server script does not block while waiting for the database.