Function
dbQuery
Sends a query that returns a result. Collect it with dbPoll or in a callback that receives the query handle.
Syntax
handle dbQuery([function callback, table callbackArgs,] element connection, string query [, mixed ...])Arguments
callbackfunction, optional = nil- Called when the result is ready. Its first argument is the query handle.
callbackArgstable, optional = nil- Extra arguments for the callback.
connectionelement- A handle from
dbConnect. querystring- SQL query with
?placeholders. ...mixed- Values for the
?placeholders.
Returns
A query handle or false.
Example
addEventHandler("onPlayerLogin", root, function()
local player = source
dbQuery(function(q)
local rows = dbPoll(q, 0)
if rows and rows[1] and isElement(player) then
setPlayerMoney(player, rows[1].kasa)
end
end, db, "SELECT kasa FROM gracze WHERE serial = ?", getPlayerSerial(player))
end)
Notes
Does not block the server. The query runs in the background and the callback fires when the database answers, always after dbQuery has returned. Queries on one connection run in order.
See also
dbPollCollects the result of adbQuery: the rows, the number of affected rows and the last inserted ID. If you just want to run a query and get the rows,dbFetchis simpler.dbFetchRuns a query and returns its result right away. One call instead ofdbQuery,dbPollanddbFree. Works with SELECT, INSERT, UPDATE and DELETE.dbFreeFrees a query result you do not intend to read.dbExecRuns a query that returns no result (INSERT, UPDATE, CREATE). Arguments replace the?placeholders.