Flat reference of every difference between MySQL R41-4 and mysql_samp. See migration.md for the explained guide and migration-examples.md for side-by-side snippets.
Argument order changed. In R41-4 the handle is the last (optional) parameter on most calls. In mysql_samp the connId is always the first parameter.
Port option name changed. In R41-4 you wrote mysql_set_option(opt, SERVER_PORT, 3307). In mysql_samp it is mysql_options_set_int(opt, MYSQL_OPT_PORT, 3307).
// R41-4newMySQLOpt:opt=mysql_init_options();mysql_set_option(opt,SERVER_PORT,3307);newMySQL:g_mysql=mysql_connect("127.0.0.1","root","pass","db",opt);// mysql_sampnewopt=mysql_options_new();mysql_options_set_int(opt,MYSQL_OPT_PORT,3307);newg_mysql=mysql_connect("127.0.0.1","root","pass","db",opt);// mysql_samp (default port 3306 — no options needed)newg_mysql=mysql_connect("127.0.0.1","root","pass","db");
The API is almost identical, with these differences:
R41-4
mysql_samp
Difference
ORM:orm_create(table, MySQL:handle)
orm_create(table, connId)
No tags
orm_destroy(ORM:id)
orm_destroy(orm_id) → bool
Now returns bool
E_ORM_ERROR:orm_errno(ORM:id)
orm_errno(orm_id) → int
No enum tag
orm_apply_cache(ORM:id, row, result_idx)
orm_apply_cache(orm_id, row)
No result_idx (single result set)
orm_load(...)
removed
Was an alias of orm_select
orm_addvar_string(orm, var, max_len, col)
unchanged
max_len now capped at 4096
ORM error enum:
R41-4
mysql_samp
ERROR_INVALID = 0
does not exist
ERROR_OK = 1
ORM_OK = 0
ERROR_NO_DATA = 2
ORM_NO_DATA = 1
The rest of the ORM natives (orm_select, orm_update, orm_insert, orm_delete, orm_save, orm_addvar_*, orm_delvar, orm_clear_vars, orm_setkey) keep the same signatures, only without the ORM: tag.
Replace #include <a_mysql> with #include <mysql_samp>.
Replace mysql_tquery with mysql_query.
Replace %s (raw) with %r in mysql_format wherever the old %s was intentionally unescaped.
Keep the connection on mysql_escape_string — it now selects the escaping rules for the server's sql_mode. Better still, move player input to prepared statements (mysql_stmt_*).
Replace cache_num_rows() with cache_get_row_count().
Convert cache_get_value_*_int / cache_get_value_*_float from by-ref to return value.
Convert cache_is_value_*_null from by-ref to return value.
Convert cache_get_row_count / cache_get_field_count from by-ref to return value.
Strip every tag (MySQL:, Cache:, ORM:, MySQLOpt:, E_ORM_ERROR:).
Replace mysql_init_options() with mysql_options_new().
Replace mysql_set_option(opt, type, ...) with mysql_options_set_int / mysql_options_set_str.
Reverse the parameter order of mysql_error (connId is now first).
Replace mysql_stat with mysql_status (connId first).
Move any code that read the cache after a synchronous mysql_query into a proper callback.
Optional:
"i" → "d" in callback formats (both work in mysql_samp).