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

Function

dbFetchValue

ServerDatabaseTrilogy Hub only

Runs a query and returns a single value: the first column of the first row. For counting (COUNT(*)), sums and single fields.

Syntax

mixed dbFetchValue(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 value from the first column of the first row, nil when there are no rows. On error false with the error message as the second value.

Example

local db = dbConnect("sqlite", "gracze.db")

addCommandHandler("ilu", function(player)
    async(function()
        local ilu = dbFetchValue(db, "SELECT COUNT(*) FROM gracze")
        outputChatBox("Zarejestrowanych graczy: " .. tostring(ilu), player)
    end)
end)

Notes

false can mean NULL or an error. A NULL value from the database also arrives as false. If the column can be empty, check the second value: on error it holds the message.

See also