Skip to content

MySQL_Run

imshooter edited this page Nov 3, 2026 · 3 revisions

Run a query and wait for it, after the queries sent before it.

Its result is the one read until the next MySQL_Run, or until the public that ran it returns. The server stops while it waits, so it suits the tables made at start up.

native bool:MySQL_Run(MySQL:handle, const query[], MYSQL_TAGS:...);

Parameters

Parameter Description
MySQL:handle Handle to run it through.
const query[] The query, formatted with the values after it.
MYSQL_TAGS:... Values for the specifiers of the query, in order.

Returns

  • true when it succeeded.
  • false when it failed, the handle does not exist, the format is not valid, or a limit of the connection refused it.

Remarks

The game thread waits until the query ends, and the queries sent before it on the handle run first, so a slow query or a long queue stalls the server for that long. It suits the start of the server, such as creating tables, and quick reads that cannot wait.

Its result is the one the MySQL_Get natives read until the next query. Inside the public of another query, it replaces the result of that public until the public returns.

Example

new MySQL:gDatabase;

public OnGameModeInit() {
    gDatabase = MySQL_ConnectFile("mysql.ini");

    MySQL_Run(gDatabase, "\
        CREATE TABLE IF NOT EXISTS players ( \
            id INT AUTO_INCREMENT PRIMARY KEY, \
            name VARCHAR(24) NOT NULL UNIQUE, \
            score INT NOT NULL DEFAULT 0 \
        )\
    ");

    new
        total
    ;

    if (MySQL_Run(gDatabase, "SELECT COUNT(*) AS total FROM players") && MySQL_GetValueInt(0, "total", total)) {
        printf("%i players are registered.", total);
    }

    return 1;
}

Related

  • MySQL_ThreadedQuery: Send a query, and call a public with context when it is done.
  • MySQL_RunQuery: Run a query built in pieces and wait for it, as MySQL_Run does, and forget it.
  • MySQL_RunStatement: Run a statement once and wait for it, as MySQL_Run does.

Clone this wiki locally