DbConnect: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Document upcoming 0.1.4 database recovery; organize wiki navigation
Release 0.1.4 BUILD133 / Protocol 36 and document authenticated event origin
 
Line 49: Line 49:
[[Category:Database Functions]]
[[Category:Database Functions]]
== Recovery from 0.1.4 ==
== Recovery from 0.1.4 ==
'''Since 0.1.4 (in development; not in public 0.1.3).''' See [[MySQL connection recovery]], [[dbReconnect]], [[dbGetConnectionState]] and [[onDatabaseConnectionStateChange]]. Set the optional fifth argument to <code>charset=utf8mb4;autoreconnect=true</code> to enable background recovery after a successful initial connection. Default false preserves older scripts. Failed SQL is never replayed and transaction/session loss requires explicit recovery.
'''Since 0.1.4.''' See [[MySQL connection recovery]], [[dbReconnect]], [[dbGetConnectionState]] and [[onDatabaseConnectionStateChange]]. Set the optional fifth argument to <code>charset=utf8mb4;autoreconnect=true</code> to enable background recovery after a successful initial connection. Default false preserves older scripts. Failed SQL is never replayed and transaction/session loss requires explicit recovery.

Latest revision as of 20:40, 21 September 2026

dbConnect

Opens a server-side MySQL connection managed by the current resource.

Syntax

DatabaseConnection dbConnect(string driver, string connectionString, string username, string password [, string options = ""])

Parameters

Name Type Required Description
driver string yes Database driver name. Currently only mysql is supported.
connectionString string yes Semicolon-separated connection options such as host, port and database.
username string yes The database account name.
password string yes The database password or configured secret reference.
options string no Optional connection behavior flags.

Returns

Returns a DatabaseConnection handle on success, or false on failure.

Examples

Connect to a configured MySQL database:

local db = dbConnect(
    "mysql",
    "host=127.0.0.1;port=3306;dbname=g1r_mp",
    "g1r_server",
    "env:G1R_DB_PASSWORD"
)

if not db then
    outputDebugString("Database connection failed", 1)
end

Notes

  • Available only in server-side resource scripts.
  • Database access is server-side only. Never put database credentials in client resources.

Recovery from 0.1.4

Since 0.1.4. See MySQL connection recovery, dbReconnect, dbGetConnectionState and onDatabaseConnectionStateChange. Set the optional fifth argument to charset=utf8mb4;autoreconnect=true to enable background recovery after a successful initial connection. Default false preserves older scripts. Failed SQL is never replayed and transaction/session loss requires explicit recovery.