MySQL / MariaDB
Hello there,
I've had very little time these past months, i hope to get more time soon to implement a lot of new features i have plans for... meanwhile i spend 10 minutes putting together a sample include for mysql/mariadb and a sample app.
If anyone wants to extend and finish the include before i get around to it, please do reply:
Include File: "database/mysql.zir"
#include 'windows\\win_kernel.zir';
type PMYSQL = pointer;
type PMYSQLRES = pointer;
type PMYSQLROW = char*;
// function refs
function* WINAPI mysql_init(PMYSQL _mysql): PMYSQL;
function* WINAPI mysql_real_connect(PMYSQL _mysql; char* host, user, passwd, db; DWord port; char* unix_socket; DWord clientflag): PMYSQL;
function* WINAPI mysql_query(PMYSQL _mysql; char* q): Int32;
function* WINAPI mysql_store_result(PMYSQL _mysql): PMYSQLRES;
function* WINAPI mysql_num_rows(PMYSQLRES res): Int64;
procedure* WINAPI mysql_free_result(PMYSQLRES result);
function* WINAPI mysql_get_server_info(PMYSQL _mysql): char*;
function* WINAPI mysql_fetch_row(PMYSQLRES result): PMYSQLROW;
////
function mysql_loadlib(char* libfile) {
DWord libmysql_handle;
libmysql_handle = LoadLibraryA(libfile);
if (libmysql_handle != 0) {
mysql_init = GetProcAddress(libmysql_handle, 'mysql_init');
mysql_real_connect = GetProcAddress(libmysql_handle, 'mysql_real_connect');
mysql_query = GetProcAddress(libmysql_handle, 'mysql_query');
mysql_store_result = GetProcAddress(libmysql_handle, 'mysql_store_result');
mysql_num_rows = GetProcAddress(libmysql_handle, 'mysql_num_rows');
mysql_free_result = GetProcAddress(libmysql_handle, 'mysql_free_result');
mysql_get_server_info = GetProcAddress(libmysql_handle, 'mysql_get_server_info');
mysql_fetch_row = GetProcAddress(libmysql_handle, 'mysql_fetch_row');
}
return libmysql_handle;
}
function mysql_freelib(Dword libhand) {
FreeLibrary(libhand);
}
sample usage:
program PE32_CUI 'mysql test';
#include 'win_def.zir';
#include 'zirutils.zir';
#include 'console.zir';
#include 'database/mysql.zir';
DWord mysql_libhandle;
mysql_libhandle = mysql_loadlib('libmariadb.dll');
const DB_HOST = 'localhost';
const DB_PORT = 3306;
const DB_USER = 'root';
const DB_PASS = '********';
const DB_NAME = 'DBNAME';
PMYSQL dbconn;
dbconn = mysql_init(nil);
mysql_real_connect(dbconn, DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT, nil, 0);
mysql_query(dbconn, 'SELECT * FROM items;');
PMYSQLRES dbres;
dbres = mysql_store_result(dbconn);
if (dbres != nil) {
eax = mysql_fetch_row(dbres);
while (eax != nil) {
edi = [eax+25*4]; //25 = column you want info from
print('Row Info: ', [char*]edi, '\r\n');
eax = mysql_fetch_row(dbres);
}
mysql_free_result(dbres);
}
mysql_freelib(mysql_libhandle);
wait_key();
ExitProcess(0);
you'll need to fill in the database username, pass etc and edit the sql query and which column to grab data from for this sample.
Regards,