DbConnect

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search

dbConnect

Opens a server-side MySQL connection managed by the current resource.

Syntax

DatabaseConnection dbConnect(string driver, string connectionString, string username, string password [, string options = ""])

Parameters

Name Type Required Description
driver string yes Database driver name. Currently only mysql is supported.
connectionString string yes Semicolon-separated connection options such as host, port and database.
username string yes The database account name.
password string yes The database password or configured secret reference.
options string no Optional connection behavior flags.

Returns

Returns a DatabaseConnection handle on success, or false on failure.

Examples

Connect to a configured MySQL database:

local db = dbConnect(
    "mysql",
    "host=127.0.0.1;port=3306;dbname=g1r_mp",
    "g1r_server",
    "env:G1R_DB_PASSWORD"
)

if not db then
    outputDebugString("Database connection failed", 1)
end

Notes

  • Available only in server-side resource scripts.
  • Database access is server-side only. Never put database credentials in client resources.