dbQuery | Multi Theft Auto: Wiki Skip to content

dbQuery

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function starts a database query using the supplied connection. Use the returned query handle with dbPoll to get the result, or dbFree if you don't want the result.

Tip

The server command debugdb 2 will output verbose information on each query to a logging file (usually logs/db.log )

Important

It is strongly recommended to use this function asynchronously, as presented in "This example starts a select query and processes the result in an inline callback function with custom arguments:"

OOP Syntax Help! I don't understand this!

Syntax

handle dbQuery ( function callbackFunction, [ table callbackArguments, ], element databaseConnection, string query, var param1 [, var param2 ...] )
Required Arguments
  • callbackFunction: An optional function to be called when a result is ready. The function will only be called if the result has not already been read with dbPoll . The function is called with the query handle as the first argument.
  • table callbackArguments, ]: MISSING_PARAM_DESC
  • databaseConnection: A database connection element previously returned from dbConnect
  • query: An SQL query. Positions where parameter values will be inserted are marked with a ?
  • param1 [, var param2 ...]: MISSING_PARAM_DESC

Returns

  • handle: value

Returns a query handle unless the connection is incorrect, in which case it return false .

Code Examples

shared

This example starts an INSERT query and frees the result:

local qh = dbQuery( connection, "INSERT INTO table_name VALUES (?,?,?)", "aaa", "bbb", 10 )
dbFree( qh )