Skip to content

Migrating from SA MP MySQL

Xyranaut edited this page Jun 1, 2026 · 2 revisions

Migrating from SA-MP-MySQL

omp-MySQL uses a modern, industry-standard API — it does not reuse SA-MP-MySQL's native names. The concepts are the same; the names and a couple of conventions changed for the better. The full one-to-one mapping of every function is in the Native reference; this page is the orientation.

Two conventions that changed (read these first)

  1. Prepared-statement parameters are 1-based (JDBC-style): the first ? is index 1, not 0.
  2. Result values use the mysql_rs_* family (a ResultSet), replacing cache_*.

The common functions, mapped

You used to call (SA-MP-MySQL) Now call (omp-MySQL)
mysql_connect mysql_connect(host, user, pass, db, cfg)TLS mandatory
mysql_connect_file mysql_connect_config("mysql.ini")
mysql_close mysql_close
mysql_tquery mysql_execute(h, query, cb, fmt, ...)
mysql_pquery mysql_execute_for(h, query, cb, fmt, ...) (player-bound)
mysql_query mysql_execute_sync(h, query)
mysql_format mysql_format (now %e escape, %q quote-ident)
mysql_escape_string mysql_escape (prefer prepared statements)
mysql_errno / mysql_error mysql_errno / mysql_error
mysql_stat mysql_server_status
mysql_get_ssl_cipher mysql_get_tls_cipher
cache_get_value_name_int etc. mysql_rs_get_int_by / mysql_rs_get_string_by / …
cache_num_rows mysql_rs_row_count
cache_insert_id mysql_rs_insert_id
(no equivalent) mysql_prepare + mysql_stmt_set_*prepared statements
(no equivalent) mysql_hash / mysql_verifyArgon2id
orm_* mysql_model_* — active-record models

A before/after example

Before (SA-MP-MySQL):

new query[128];
mysql_format(g_DB, query, sizeof query,
    "SELECT * FROM users WHERE name = '%e'", name);
mysql_tquery(g_DB, query, "OnLogin", "d", playerid);

public OnLogin(playerid) {
    if (cache_num_rows()) {
        new money = cache_get_value_name_int(0, "money");
    }
}

After (omp-MySQL) — same idea, or better, a prepared statement:

new PreparedStatement:st = mysql_prepare(g_DB,
    "SELECT * FROM users WHERE name = ?");
mysql_stmt_set_string(st, 1, name);
mysql_stmt_execute(st, "OnLogin", "d", playerid);

public OnLogin(playerid) {
    new rows; mysql_rs_row_count(rows);
    if (rows) {
        new money; mysql_rs_get_int_by(0, "money", money);
    }
    return 1;
}

Things to also update while migrating

  • Add TLS — make sure your MySQL server supports it (5.7+ does by default) and pick an SSL_MODE (see Configuration). There's no "off".
  • Move secrets to ${ENV} — stop hardcoding the password.
  • Switch password hashing to mysql_hash/mysql_verify (Argon2id) instead of whatever you were doing in Pawn.
  • Replace string-built queries with prepared statements where player input is involved.

See the complete function list: Native reference.

Clone this wiki locally