Repository navigation
MySQL_ConnectFile
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");| Parameter | Description | Default |
|---|---|---|
const file[] |
Path of the file, from the folder of the server. | "mysql.ini" |
- The handle.
-
INVALID_MYSQL_IDwhen the file cannot be read or has a setting that is not valid.
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.
hostname = 127.0.0.1
username = game
password = ${MYSQL_PASSWORD}
database = game
pool = 2
slow_query = 50new MySQL:gDatabase;
public OnGameModeInit() {
gDatabase = MySQL_ConnectFile("mysql.ini");
if (gDatabase == INVALID_MYSQL_ID) {
print("mysql.ini is missing or not valid.");
}
return 1;
}- MySQL_Connect: Connect to a database.
- MySQL_Close: Close a handle after running every query still waiting.
- MySQL_IsConnected: Whether the connection of the ordered queries is open.
MySQL 0.2.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- Results
- JSON cells
- Prepared statements
- Passwords
- Errors
- TLS
- Coming from R41
- Performance
Reference
Functions