Ghmattimysql: My MySQL Implementation for FiveM [1.3.2]

does this mean if i have mysql and i dont get the option to use ghmattimysql, this will add the databse for me under ghmatti? as i use zaphosting for my server and cant get ghmattimysql

Hello, great script, I followed the tutorial, I deleted json and configured ghmattimysql with the mysql_connection_string, in all files __resource.lua I replaced ā€˜@ mysql-async / lib / MySQL.lua’, with ā€˜GHMattiMySQL’, but even so I receive these errors, I would appreciate your help.

use mysql-async, the latest versions are not compatible. you can use the C# version instead. which has a replacement drop in.

1 Like

I have tried with the advice he has given me, but with the same result, a picture is worth a thousand words.
Thanks again for your time, I thank you very much for your help, I want to use GHMattiMySQL on my server and fly happily.


just use mysql-async for esx. It is the same stuff, only that ghmattimysql uses a different syntax and replies differently (way better imho).

For the dropin replacement use this https://github.com/GHMatti/FiveM-MySQL/releases C# implementation, which i should update at some point by re-compiling it.

I second the very weak documentation

This is definitely helpful, but I would like to see it in full context, with the constructor.

Can we get a full example, the link gives a 404 error.
Is there a reference file that needs included as well?

That was for the old C# implementation. That i should recompile at some point.

Just use exports, it is easier imho.

Thanks for replying.

Going back to the original post, I use this file…


Add this as a resource and call the exports in ghmattimysql-server.lua?

Using this code I get results but can not figure out how the extract the data from results.

Exports["ghmattimysql"].executeSync($"SELECT * FROM client WHERE name = '{player.Name}';", new Action<dynamic>((result) =>
                {
                    Log.Info($"((dynamic)result).Count = {((dynamic)result).Count}");
                    if(((dynamic)result).Count == 0)
                    {
                        Log.Info("Player not found in database.");
                    }
                    if (((dynamic)result).Count > 0)
                    {

                    }
                }));

you should be using the async calls. the exectue sync does return something, should work in C# (maybe, did not touch it for a long time, forgot a lot) does not work in js.

Exports["ghmattimysql"].execute("SELECT * FROM client WHERE name = ?", { player.Name }, new Action<dynamic>((result) =>
                {
                    Log.Info($"((dynamic)result).Count = {((dynamic)result).Count}");
                    if(((dynamic)result).Count == 0)
                    {
                        Log.Info("Player not found in database.");
                    }
                    if (((dynamic)result).Count > 0)
                    {

                    }
                }));

should work, i think.

or you can do stuff like this:

Exports["ghmattimysql"].execute("SELECT * FROM ?? WHERE ?? = ?", { "client", "name", player.Name }, new Action<dynamic>((result) =>
                {
                    Log.Info($"((dynamic)result).Count = {((dynamic)result).Count}");
                    if(((dynamic)result).Count == 0)
                    {
                        Log.Info("Player not found in database.");
                    }
                    if (((dynamic)result).Count > 0)
                    {

                    }
                }));

Can we get some definitive and recommended examples to implement this resource in C#? A search of this forum results is tons of errors, issues, and implementation questions all due to lack of documentation and examples. You have to remember, most people here are not expert programmers like yourself and cannot read between the code lines.

I think I have to concur with mprofitt1, in terms of C# docs. I understand that its a free library and the author is under no obligation to maintain it or provide support, but it would really help people (including me) with a good pushstart.

I’m alright up until it gets to making SELECT statements. If it helps, here’s a really basic insert statement.

Simple Insert

string query = "INSERT INTO `devdb`.`users` " +
        "(`user_id`, " +
        "`steam_id`) " +
    "VALUES " +
        "(1, " +
        "'1101111111' " +
    ");";

Exports["GHMattiMySQL"].Query(query);

And if you want to include any parameters, you’ll need to pass a Dictionary type. The Key is how you reference it in the query (@steamidentifier), the Value is the parameter’s value.

Select with Parameters

IDictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("steamidentifier", source.Identifiers["steam"]);

string query = "SELECT * FROM users WHERE steam_id=@steamidentifier";

Exports["GHMattiMySQL"].QueryResult(query, parameters);

Make sure that the Key value that you’re using isn’t used anywhere in the query of DB. For example, using @steam_id would cause issues as it is the same name as the field in the table, so we use something slightly different.

All I need help with is how to iterate through the selected rows from QueryResult. I’ve seen people using the new Action<dynamic>((result) => {} method, but I’m finding that the code within the braces isn’t being iterated through? Unless its getting called incorrectly.

If there’s someone out there who is familiar with this system, and could perhaps provide a C# demonstration of the following, I’m sure there’ll be many, many, grateful .NET developers!

  • Handling results from QueryResult
  • Best practice/recommended usage of Async type functions.
1 Like

Update to 1.2.1

  • Fixed #14 works now with and without the @.
  • Rewrote transactions to be less spaghetti, will be moving that to mysql-async soon.
  • Added codebeat for code quality review.
  • Switched to stylus instead of using plain old css.
  • Errors are now always red until all debug output is only rerouted to a file.

how do i fix this after updating the wrapper?? Invalid cast from 'Double' to 'DateTime'.
using DateTime.FromOADate doesn’t work

Just create a 0 DateTime (unix epoch) and add the number of milliseconds to it. Might be seconds, I do not remember, but i think js returns milliseconds.

was easier before… i just had to do Convert.ToDateTime(result.value) :sweat_smile:
thank you @zr0iq for the answer :slight_smile:

Added examples into the readme. Not really fleshed out, but should be enough.

In C# using exports I’d rather hang myself. I got it working with a recovered version of the library.