Repository navigation
Configuration
A connection is opened with mysql_connect, which takes a set of options from mysql_init_options, or with mysql_connect_file, which reads mysql.ini.
new MySQL:gDatabase;
public OnGameModeInit() {
new const
MySQLOpt:options = mysql_init_options()
;
mysql_set_option(options, SERVER_PORT, 3306);
mysql_set_option(options, POOL_SIZE, 4);
mysql_set_option(options, SLOW_QUERY, 50);
gDatabase = mysql_connect("127.0.0.1", "game", "secret", "game", options);
if (mysql_errno(gDatabase) != 0) {
print("The database is not there yet. Queries will connect when it is.");
}
return 1;
}| Option | In mysql.ini
|
Value | Default |
|---|---|---|---|
SERVER_PORT |
server_port |
port of the server | 3306 |
CHARSET |
charset |
character set of the text | latin1 |
MULTI_STATEMENTS |
multi_statements |
several statements in one query | false |
POOL_SIZE |
pool_size |
connections for parallel queries, 0 to 32
|
4 |
AUTO_RECONNECT |
auto_reconnect |
always on | true |
ERROR_CALLBACK |
error_callback |
call the public of a failed query too | false |
CONNECT_TIMEOUT |
connect_timeout |
seconds to connect | 5 |
READ_TIMEOUT |
read_timeout |
seconds to wait for an answer | none |
WRITE_TIMEOUT |
write_timeout |
seconds to send a query | none |
SLOW_QUERY |
slow_query |
milliseconds from which a query is logged | none |
MAX_QUERY_LENGTH |
max_query_length |
bytes a query may have | none |
MAX_PENDING |
max_pending |
queries waiting or running | none |
MAX_QUERIES_PER_SECOND |
max_queries_per_second |
queries sent in a second | none |
The options of TLS are on the TLS page. A query past a limit is refused: it is not sent, the native returns false, and a line is logged at most once a second.
mysql_connect_file looks for a relative path in scriptfiles first, then in the folder of the server. A line is key = value, with hostname, username, password, database and the keys above. Lines that start with #, ; or [ are skipped. ${NAME} in a value is replaced by the environment variable NAME, and a variable that is not set makes the file invalid.
hostname = 127.0.0.1
username = game
password = ${MYSQL_PASSWORD}
database = game
pool_size = 4mysql_global_options sets what holds for every handle. DUPLICATE_CONNECTIONS lets a second mysql_connect with the same server, account and database open another handle, where by default it gives the handle open already. mysql_log chooses what is logged.
mysql 0.6.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- The cache
- JSON cells
- Prepared statements
- Transactions
- The ORM
- Passwords
- Errors
- TLS
- Coming from another plugin
- Performance
Reference
Functions
Connections
Queries
Cache
- cache_get_row_count
- cache_get_field_count
- cache_get_result_count
- cache_get_field_name
- cache_get_field_type
- cache_get_field_index
- cache_set_result
- cache_get_value_index
- cache_get_value_index_int
- cache_get_value_index_float
- cache_get_value_index_bool
- cache_is_value_index_null
- cache_get_value_name
- cache_get_value_name_int
- cache_get_value_name_float
- cache_get_value_name_bool
- cache_is_value_name_null
- cache_get_row
- cache_save
- cache_delete
- cache_set_active
- cache_unset_active
- cache_is_any_active
- cache_is_valid
- cache_affected_rows
- cache_insert_id
- cache_warning_count
- cache_get_query_exec_time
- cache_get_query_string
- cache_get_errno