Skip to content

Latest commit

 

History

History

README.md

mysql_samp examples

Runnable Pawn snippets showing how to use the plugin on SA-MP and Open Multiplayer. The plugin natives (mysql_*, cache_*, orm_*) and the OnQueryError forward are identical across both servers — every snippet here exercises only the plugin API.

File Topic
01_basic_connection.pwn Connect / close, with and without mysql_options_new()
02_threaded_query.pwn mysql_query + callback, read cache by column name / index
03_parallel_query.pwn mysql_pquery for unordered, parallel work
04_escape_and_format.pwn mysql_format (%s auto-escape, %e, %r, %d, %f)
05_orm.pwn ORM: bind Pawn vars to columns, orm_save / orm_select
06_ssl.pwn Enable TLS via MYSQL_OPT_SSL / MYSQL_OPT_SSL_CA (v1.1.1+)
07_error_handling.pwn OnQueryError, mysql_errno, mysql_error

Compiling

The examples assume the include path is set up so that <mysql_samp> resolves to ../include/mysql_samp.inc.

pawncc -i../include 01_basic_connection.pwn

Or copy mysql_samp.inc into your pawno/include/ (SA-MP) or qawno/include/ (open.mp) folder and compile from inside the gamemode tree.

Installing the plugin

SA-MP

Drop mysql_samp.so (Linux) or mysql_samp.dll (Windows) into plugins/ and register it in server.cfg:

plugins mysql_samp.so

Open Multiplayer — native component (recommended)

Drop the binary into the components/ folder. open.mp auto-discovers it on start and loads it via ComponentEntryPoint. No config.json entry is required — listing the file in components is not a thing; the folder itself IS the registration.

Open Multiplayer — legacy mode

Drop the binary into plugins/ and declare it under legacy_plugins in config.json (legacy plugins must be listed explicitly, unlike native components):

{
  "pawn": {
    "legacy_plugins": ["mysql_samp"]
  }
}

Conventions used across the examples

  • Connection credentials are placed at the top as #defines — replace with values from a config file in real code.
  • One global g_MysqlConn holds the connection id; 0 means "not connected".
  • Threaded callbacks read from the implicit active cache; no need to call cache_set_active unless you persisted the cache with cache_save.
  • All queries are non-blocking — the gamemode never waits on MySQL.