[Solved]Mysql-async index a nil value (global 'MySQL)

GTA V version? 1.46
Up to date? yes
Legit or Pirate copy? Legit
Steam/CD/Social Club? Steam
Windows version? Yes
Did you try to delete caches.xml and try again? yes
Error screenshot (if any) mysql-async attempting to index nil value (mysql)
System specifications
What did you do to get this issue? Tried getting values from a table
What server did you get this issue on?
CitizenFX.log file
.dmp files/report IDs

Hi, I’m trying to pull some values from a table in my db using mysql-async. However, it keeps returning the below error.

@doorchat/server.lua:40: attempt to index a nil value (global 'MySQL')

The code is in the server side lua, and the __resource.lua is set up to use the async resource

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

client_scripts {
    'client.lua'
}

server_script {
    'server.lua',
    '@mysql-async/lib/MySQL.lua',
}

The code in the server side causing the issue is:

MySQL.Async.fetchAll("SELECT * FROM `users` WHERE `identifier` = @identifier",{ ['@identifier'] = identifier }, function(result)
		if result[1] ~= nil then
			if result[1].firstname ~= '' then
				local data 			= result[1]
				local charName 		= tostring(data.firstname) .. " " .. tostring(data.lastname)
				local charDOB 		= tostring(data.dateofbirth)
				local charSex		= tostring(data.sex)
                local charHeight	= tostring(data.height)
                local job           = tostring(data.job)

I’ve tried this resource on both our dev server as well as my home server incase there was some kind of connection issue on the dev server, but the error is the same.

Anyone able to point me in the right direction please? Thanks in advance

4 Likes

Hello, this is a friendly reminder because this is your first time creating a topic (or it has been a while since your last topic) in this category.

Please note that most of the support is provided by the FiveM community on a voluntary basis. We ask you to be patient; there is no guarantee we have a solution to your problem(s). To avoid unnecessary/duplicate topics, please browse the forums before creating a topic.

To improve your chances of your issue(s) being solved, please provide as much information as possible about the issue(s) you are having. Also —whenever possible— please use the template given to you when creating a topic.

Thanks for keeping these forums tidy!
:mascot:

Are you starting the MySQL resource before the resource that needs it?

Hi,

Yes, sorry I forgot to mention that, mysql-async is on line 18 and the script we’re working on starts on the very bottom line. We’re also using the ESX framework, which has some resources that uses the exact same line to pull from the table.

1 Like
server_script { 
     '@mysql-async/lib/MySQL.lua',
     ,'server.lua'
 }

Give that a shot.

8 Likes

:heart_eyes::heart_eyes:

Thank you so much!!! That worked, we’re now getting a buffer error, but we’re getting something. We’re good from here!

So would I be correct in assuming, as it’s a dependency, that’s why it’s required to go above the server.lua?

1 Like

That’s correct, lua is very linear in it’s behavior. If you need something in the script, it needs to be listed prior.

1 Like

Perfect!!

Yeah, we’re noticing luas “delicate” nature rather rapidly.

Anyways, thank you so much again :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.