ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server functions
  3. dbFetchOne

Function

dbFetchOne

ServerDatabaseTrilogy Hub only

Runs a query and returns only the first row. Handy when you look for a single record, for example a player's account.

Syntax

table dbFetchOne(element connection, string query, mixed ...)

Arguments

connectionelement
A handle from dbConnect.
querystring
SQL query with ? in place of values.
...mixed
Values for the ? placeholders.

Returns

The first row (column = value), nil if the query returned no rows, or false and the error message.

Example

local db = dbConnect("mysql", "glowna")

addEventHandler("onPlayerJoin", root, function()
    local player = source
    async(function()
        local konto = dbFetchOne(db, "SELECT kasa, skin FROM gracze WHERE serial = ?", getPlayerSerial(player))
        if not isElement(player) then return end
        if konto then
            setPlayerMoney(player, konto.kasa)
            setElementModel(player, konto.skin)
        else
            outputChatBox("Witaj pierwszy raz na serwerze!", player)
        end
    end)
end)

See also