/fivem-mysql

MySQL middleware for FiveM

Primary LanguageJavaScript

MySQL JavaScript middleware for FiveM

This script is significantly faster than mysql-async based on my testing.

Install / Configure

1. Set the connection datas in settings.json file

for example:

{
    "host": "localhost",
    "user": "root",
    "password": "",
    "database": "roleplay"
}
2. Add this resource import.lua file to your resource

fxmanifest.lua

server_script  '@mysql/import.lua'

Functions

dbQuery

Arguments

  • callback: function, returns mysql query result optional
  • queryString: string
  • args: table
dbQuery(callback, queryString, args)

Example

With callback

dbQuery(
	function(result)
	  print(#result) --print result table lenght
	end,
	"SELECT * FROM users WHERE identifier = ? LIMIT 1",
	{
		identifier,
	}
)

Without callback

local result = dbQuery(
	"SELECT * FROM users WHERE identifier = ? LIMIT 1",
	{
		identifier,
	}
)

Query arguments not table

local result = dbQuery("SELECT * FROM users WHERE identifier = ? LIMIT 1", identifier)

dbExec

Arguments:

  • queryString: string
  • args: table

Returns:

boolean, (note: if it runs successfully it returns a true value)

dbExec(queryString, args)

Example

dbExec("INSERT INTO users SET name = ?", {
	GetPlayerName(player),
})

OR

dbExec("INSERT INTO users SET name = ?", GetPlayerName(player) )