Repository navigation
MySQL_Connect
Connect to a database.
The connection is made before the native returns. When it fails, the handle is still given and every query tries to connect again, half a second after the first failure and twice as long after each next one, up to five seconds. options takes settings as key=value separated by semicolons:
-
charset,latin1by default, which is the code page of the game. -
multi_statements,falseby default, andpool, the connections for parallel queries,0by default. -
connect_timeout,read_timeoutandwrite_timeout, in seconds. A query whose answer takes longer thanread_timeoutfails, and the connection opens again. -
slow_query, the milliseconds from which a query is logged, andlog_errors,trueby default. -
max_query_lengthin bytes,max_pending, the queries waiting or running, andmax_queries_per_second. A query past one of them is refused: it is not sent, the native returnsfalse, and a line is logged, at most one a second.0, the default, sets no limit. -
sslto require TLS. The connection then never runs without it, and fails when the server answers without TLS.ssl_verifyalso verifies the certificate of the server and its name, against the certificate authorities ofssl_ca, a file, orssl_capath, a folder, and the revocation lists ofssl_crlorssl_crlpath. Onlocalhost,127.0.0.1and::1the name is not checked, and the authority only whenssl_caorssl_capathis given.ssl_fingerprintrequires the certificate of the server to have that SHA1 to SHA512 fingerprint, in hexadecimal with or without colons, which suits a certificate signed by no authority.ssl_certandssl_keygive the certificate of the client,ssl_cipherthe ciphers allowed andtls_versionthe versions, asTLSv1.2,TLSv1.3. Any of these settings requires TLS too. Without them the connection does not use TLS, as a database on the same machine needs none.
native MySQL:MySQL_Connect(
const host[],
const user[],
const password[],
const database[],
port = 3306,
const options[] = ""
);| Parameter | Description | Default |
|---|---|---|
const host[] |
Name or address of the server. | |
const user[] |
Account to log in with. | |
const password[] |
Password of the account. | |
const database[] |
Database the queries use. | |
port |
Port of the server. | 3306 |
const options[] |
Settings of the connection. | "" |
- The handle.
-
INVALID_MYSQL_IDwhen an option is not valid.
The first connection is opened inside the native, so the handle can run queries at once. A handle that could not connect still works. Every query tries to connect again, half a second after the first failure and twice as long after each next one, up to five seconds, and fails with the error of the connection until it connects. See Configuration for every option.
The handle is closed when the script that made it unloads.
new MySQL:gDatabase;
public OnGameModeInit() {
gDatabase = MySQL_Connect("127.0.0.1", "game", "secret", "game", 3306, "pool=2;slow_query=50");
if (!MySQL_IsConnected(gDatabase)) {
print("The database is not there yet. Queries will connect when it is.");
}
return 1;
}- MySQL_ConnectFile: Connect to a database with the settings of a file.
- MySQL_Close: Close a handle after running every query still waiting.
- MySQL_IsConnected: Whether the connection of the ordered queries is open.
- MySQL_GetConnectionError: The message of the last time the handle failed to connect.
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