Main Menu

MySQL Module

Started by Vortrex, Jan 28, 2023, 08:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Vortrex

This is a simple MySQL module for those who want to use it for their server. Most of the functions have been lightly tested, but if you run into any issues please leave a reply on this topic.

Download:
https://github.com/VortrexFTW/mod_mysql/releases

Instructions:
Place into your server's "modules" folder and put "<module src="<I>module_folder_name/module_file_name</I>" />" into the modules section of your server XML. Be sure to include the folder your modules are stored in (it's relative to the main server directory) and do **not** include a file extension.
<modules>
    <module src="modules/mod_mysql" />
</modules
For Windows, you'll need to download the libmysql.dll file that goes with your server's platform and architecture. A list of these is available on the releases page, found on the link above. This file needs to be in the main server folder, not the module folder.

For Linux, you'll need to install libmysqlclient18 ... Use your distro's package manager or download from the mysql website. Unlike Windows, you don't need any extra files in the server directory for this to work.

JavaScript Example:
let db = module.mysql.connect("localhost", "username", "password", "database", 3306);
let result = db.query("SELECT id, something FROM test");
if(result.numRows > 0) {
    let row = result.fetchRow();
    console.log("ID is " + String(row[0]));
}
result.free();
db.close();

Available Functions:
connectionHandle = module.mysql.connect(string host, string user, string password, string database, int port);
resultHandle = connectionHandle.query(string query);

void connectionHandle.close(void);
int connectionHandle.affectedRows;
int connectionHandle.insertId;
bool connectionHandle.ping;
string connectionHandle.error;
string connectionHandle.info;
int connectionHandle.errorNum;
int connectionHandle.warningCount;
string connectionHandle.escapeString(string unsafeString);
void connectionHandle.selectDatabase(string database);
void connectionHandle.changeUser(string username, string password);

int resultHandle.numRows;
int resultHandle.numFields;
table resultHandle.fetchAssoc();
array resultHandle.fetchRow();
void resultHandle.free();