Skip to content

MySQL_ConnectFile

imshooter edited this page Oct 24, 2026 · 1 revision

Connect to a database with the settings of a file.

The file has a key = value setting on each line, as the mysql.ini of the R41 plugin: hostname, username, password, database, server_port, multi_statements, pool_size, ssl_enable, ssl_ca_file, ssl_ca_path, ssl_cert_file, ssl_key_file and ssl_cipher, besides the options of MySQL_Connect. A value takes ${NAME} from the environment of the server, so a password needs not be written in the file:

password = ${MYSQL_PASSWORD}

A variable that is not set makes the file not valid.

native MySQL:MySQL_ConnectFile(const file[] = "mysql.ini");

Parameters

Parameter Description Default
const file[] Path of the file, from the folder of the server. "mysql.ini"

Returns

  • The handle.
  • INVALID_MYSQL_ID when the file cannot be read or has a setting that is not valid.

Remarks

A line is key = value. Lines that start with #, ; or [ are skipped, so a section header of an INI file does no harm. ${NAME} in a value is replaced by the environment variable NAME, and a variable that is not set makes the file invalid, so a password never ends up empty by mistake.

The keys are those of the options of MySQL_Connect, plus hostname, username, password, database and port. The names of the R41 plugin, such as server_port, pool_size and ssl_ca_file, are read too. See Configuration.

Example

hostname = 127.0.0.1
username = game
password = ${MYSQL_PASSWORD}
database = game
pool = 2
slow_query = 50
new MySQL:gDatabase;

public OnGameModeInit() {
    gDatabase = MySQL_ConnectFile("mysql.ini");

    if (gDatabase == INVALID_MYSQL_ID) {
        print("mysql.ini is missing or not valid.");
    }

    return 1;
}

Related

Clone this wiki locally