Main Menu

MySQL Module

Started by Vortrex, January 19, 2019, 08:58:41 PM

Previous topic - Next 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();

Vortrex

#1
  • Added query.fetchAssoc() function

Vortrex

#2
  • Updated to work with new SDK format

 

Vortrex

#3
  • Renamed the module to mod_mysql to support both GTAC and TRML

Rhytz

#4
Instructions for x64:
  • Download mod_mysql_x64.dll from the module's github releases page.
  • Download x64 libmysql.dll from the github source (link below)
  • Place the module dll into a folder called "modules" and the libmysql.dll in the main server folder.
  • Add module to server config. It uses a relative path and exact file name, without file extension.
<module src="modules/mod_mysql_x64" />
libmysql.dll:  https://github.com/VortrexFTW/mod_mysql/blob/master/Projects/mysql/lib/x64/libmysql.dll
libmysql.dll goes in main server folder, not in the modules folder