M MY Multiplayer: Wiki
Side
Kind

dbPrepareString

Server

Fills an SQL's placeholders with escaped values, without running it.

string|false dbPrepareString(element connection, string sql, any ...)

Parameters

NameTypeDescription
connectionelementA connection from dbConnect.
sqlstringThe SQL statement, with ? and ?? as placeholders.
...anyThe placeholders' values: strings, numbers, booleans or nil.

Returns

The ready SQL, or false if the number of values does not match the placeholders.

Placeholders

  • ? takes the next value, escaped: nil becomes NULL, booleans become 1 or 0 and strings are quoted.
  • ?? takes a string as an escaped table or column identifier.
  • The number of values must match the number of placeholders.

Example

local where = dbPrepareString(db, "WHERE ?? = ?", "account", accountId)
dbExec(db, "DELETE FROM players " .. where)

See also