M MY Multiplayer: Wiki
Side
Kind

dbConnect

Server

Opens a connection to an SQLite or MySQL database. Queries run on the connection's own thread.

element|false dbConnect(string type, string target [, string user = "", string password = ""])

Parameters

NameTypeDescription
typestring"sqlite" or "mysql".
targetstringFor SQLite, the file's path inside the calling resource (folders are created). For MySQL, key=value pairs separated by ;: dbname, host, port and charset (utf8mb4, utf8mb3, utf8, latin1 or ascii).
userstringThe MySQL user.default ""
passwordstringThe MySQL password.default ""

Returns

The connection element, or false if it could not be opened (the reason goes to the log).

The connection closes when its element is destroyed or the resource stops.

Example

local db = dbConnect("sqlite", "data/players.db")
dbExec(db, "CREATE TABLE IF NOT EXISTS players (account TEXT PRIMARY KEY, money INTEGER)")

local mysql = dbConnect("mysql", "dbname=game;host=127.0.0.1;port=3306;charset=utf8mb4", "game", getConvar("db_password"))

See also