Skip to content

Coming from R41

imshooter edited this page Oct 24, 2026 · 1 revision

The R41 plugin and this component can be loaded together, as their names do not meet. A gamemode can move one system at a time, and each handle connects on its own.

What changes

  • A query takes one context value instead of a format and a list of arguments for its public. A script that needs more keeps them in an array and passes the index.
  • The component formats the query itself, so mysql_format and its array are not needed before sending. %q escapes and quotes a string in one step.
  • The cell natives return their value, instead of writing it to a variable passed by reference.
  • Natives read the result of the public they run in, with no cache to save or set as active.
  • mysql.ini is read as it is, with ${NAME} from the environment besides.

With R41:

mysql_format(gDatabase, query, sizeof (query), "SELECT score, money FROM players WHERE name = '%e'", name);
mysql_tquery(gDatabase, query, "OnPlayerLoaded", "i", playerid);

With MySQL:

new MySQL:gDatabase;

forward OnPlayerLoaded(playerid);

stock LoadPlayer(playerid, const name[]) {
    MySQL_Query(gDatabase, "OnPlayerLoaded", playerid, "SELECT score, money FROM players WHERE name = %q", name);
}

public OnPlayerLoaded(playerid) {
    if (MySQL_GetRowCount() == 0) {
        return 1;
    }

    SetPlayerScore(playerid, MySQL_GetInt(0, "score"));
    GivePlayerMoney(playerid, MySQL_GetInt(0, "money"));

    return 1;
}

Connections

R41 MySQL
mysql_connect with mysql_init_options and mysql_set_option MySQL_Connect with its settings in a string
mysql_connect_file MySQL_ConnectFile
mysql_close MySQL_Close
mysql_errno(handle) after connecting MySQL_GetConnectionErrno
mysql_unprocessed_queries MySQL_GetPendingCount
mysql_stat MySQL_GetStats
mysql_set_charset the charset setting
mysql_log the log_errors and slow_query settings

Queries

R41 MySQL
mysql_tquery MySQL_Query, or MySQL_Send without a public
mysql_pquery MySQL_ParallelQuery
mysql_query MySQL_Run
mysql_format MySQL_Format, or the format of the query native itself
mysql_escape_string %e, or %q with the quotes
mysql_tquery_file none, a file of SQL is read by the script and sent with multi_statements
orm_* Prepared statements

Results

R41 MySQL
cache_get_row_count(rows) rows = MySQL_GetRowCount()
cache_get_field_count(fields) fields = MySQL_GetFieldCount()
cache_get_field_name MySQL_GetFieldName
cache_get_value_name(row, name, text) MySQL_GetString (row, name, text)
cache_get_value_name_int(row, name, value) value = MySQL_GetInt(row, name)
cache_get_value_name_float(row, name, value) value = MySQL_GetFloat(row, name)
cache_is_value_name_null(row, name, null) null = MySQL_IsNull(row, name)
cache_get_value_index and its kin MySQL_GetRow, which reads the fields in order
cache_affected_rows MySQL_GetAffectedRows
cache_insert_id MySQL_GetInsertID
cache_warning_count MySQL_GetWarningCount
cache_get_query_exec_time MySQL_GetQueryTime, in milliseconds
cache_get_query_string MySQL_GetQuery
cache_get_result_count MySQL_GetResultSetCount
cache_set_result MySQL_SelectResultSet
cache_save MySQL_KeepResult
cache_set_active MySQL_UseResult
cache_unset_active MySQL_UseResult (INVALID_RESULT_ID)
cache_delete MySQL_DestroyResult
mysql_errno inside a public MySQL_GetErrno

Callbacks

OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle) becomes OnMySQLError(MySQL:handle, errorid, const error[], const query[], const callback[]). It is called before the public of the query, which R41 does not call at all for a query that failed.

Beyond R41

Clone this wiki locally