Ghmattimysql: My MySQL Implementation for FiveM [1.3.2]

System.Buffer.dll is a typical Microsoft dll and you can find it in either the mysql-aync git repo or branch 2 of this one.

As for your event, as its only doing one column and row why not use scalar?

scalar

You use this function when you want only a singular value returned. This means you can call it when when selecting exactly one row and one column.

scalar(query: String, parameters: Object | Array | undefined, callback: function | undefined)

It works internally the same as execute, and if this fails, so does execute. It just extracts the first column of the first response row.

did that…
now error change to my result…

Error running call reference function for resource XNLRankBar: citizen:/scripting/lua/scheduler.lua:403: @XNLRankBar/server.lua:67: attempt to index a nil value (local 'result')
stack traceback:
        @XNLRankBar/server.lua:67: in upvalue 'ref'
        citizen:/scripting/lua/scheduler.lua:389: in function <citizen:/scripting/lua/scheduler.lua:388>
        [C]: in function 'xpcall'
        citizen:/scripting/lua/scheduler.lua:388: in function <citizen:/scripting/lua/scheduler.lua:387>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:403: in function <citizen:/scripting/lua/scheduler.lua:372>
Error: Unhandled error in timer: Error: BUFFER_SHORTAGE
Error: BUFFER_SHORTAGE
    at n.e [as reserve] (citizen:/scripting/v8/msgpack.js:29:12766)
    at h (citizen:/scripting/v8/msgpack.js:29:15761)
    at n.r [as decode] (citizen:/scripting/v8/msgpack.js:29:13908)
    at n.fetch (citizen:/scripting/v8/msgpack.js:29:6972)
    at n.u [as read] (citizen:/scripting/v8/msgpack.js:29:12076)
    at Object.n [as decode] (citizen:/scripting/v8/msgpack.js:29:7097)
    at unpack (citizen:/scripting/v8/main.js:20:33)
    at citizen:/scripting/v8/main.js:51:20
    at setImmediate (ghmattimysql.js:278:1292)
    at Object.callback (citizen:/scripting/v8/timer.js:96:21)

Did you update to only return the xp column and also remove the array count on result?

Try to also print the result to the FXServer console.

i keep getting this error message

That ones pretty clear, your connection is being refused to the server. Is the IP/Port correct, do you require the port as the one shown is the default and shouldn’t be in the IP parameter.

Scalar is used when you need to return only one value.

Exports["ghmattimysql"].scalar($"SELECT a FROM table1 WHERE condition = '{condition}';", new Action<dynamic>((result) =>
                {
                    //Code inside here is executed after the query
                    if (result != null)
                        //Query returned a value
                    else
                        //Query did not return any value
                }));

Execute is used when you need to return an array of values.

Exports["ghmattimysql"].execute($"SELECT a FROM table1;", new Action<dynamic>((result) =>
                {
                    if (result != null)
                        //Result becomes an array and you use it like any other array
                        //Example: result[index].money
                        //Where index is the row of the result
                        //And money is the column’s name
                        //result.Count returns how many rows the query has returned
                    else
                        //Query did not return any value
                }));

Hope these examples are useful to you.

1 Like

crash on my server when I’m putting the GHMattiMySQL and vrp_ghmattimysql and vrpex base!

xPlayer.getIdentifier()

did you find a fix to this? im having the same issue

I don’t use this with the exports but I do have it working based off the examples I found in an older commit within the history.

As for any LUA code, I won’t be able to assit as I do everything in C#

trying to get this to work in my zap-hosting server so i can implement copes-fivem, but im getting this error. any ideas? thanks


i have these files in my rescources and i entered my info in the config
image

Can someone please explain me which is better? This or zr0iq’s other project “fivem-mysql-async”? Is this only sync? Or what are the main differences and when to use what?

@Super_TSGamer use the C# version, that is linked in the respository for vRP.

@ForFi It uses the js syntax. mysql-async is originally from brouznouf and only works with lua. They are almost identical given the code. I mean I do both.

Update to 1.2.0

  • Breaking: Added the standard typecast for Lua, so it can be used for Lua, this might break some Date / Time field queries in other languages, but who can easier cope with the changes.
  • Added a GUI available for admins with the mysql command.
  • Switched to mysql 2.17.1
  • Added slow query warnings
  • Added rerouting debug output to a log file

You’re saying mysql-async only works with Lua? Well I guess I’ll be using this version then. I code everything in JavaScript so yeah…

@SLuG can you explain me how did you changed the calls ? Im not sure how to do because i have the node.js release.

@zr0iq

local result = exports.ghmattimysql:execute('SELECT * FROM users')

		if(result[1])then
			for _, v in ipairs(result) do
				if(v.jail and v.jail ~= 0)then
					local data = json.decode(v.jail)
					if(data and data ~= 0)then
						local identifier = v.identifier
						Jail[identifier] = JailPlayer(data.prison, data.time)
					end
				end
			end
		end

this give me nil value error

everything went fine, it just does not have server.lua

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.