MySQL Too Slow?

Basically I’m attempting to call the name of a team from a MySQL database. All tables and syntax are proper, it’s just that my function is returning the string (the team name) after I call ChatPrint. However, by debugging concommand function calls the MySQL “get” function first, so is it that the MySQL is too slow? And how do I make the function wait until a value has been returned?


function GetFactionName(factionID)
	local query1 = db:query("SELECT FactionName FROM gfactions_factionlist WHERE FactionID = '"..factionID.."'")
	query1.onSuccess = function(q) local results = query1:getData() 
	local besults = results[1]
	//if !besults then return 0 end
	print("GetFactionName")
	print(besults["FactionName"])
	return besults["FactionName"]
	end
	query1.onError = function(Q,E) print("Error Loading Faction") print(E) end
	query1:start()
end

function Debug_GFI( ply, cmd, args )
	local fID = args[1]
	local info = GetFactionName(tonumber(fID))
	print("Debug_GFI")
	print(info)
	ply:ChatPrint(info)
end
concommand.Add("gfi", Debug_GFI)

When I call Debug_GFI through the console command “gfi 4” this is what pops up in console:

TestPls is the name of the faction at entry 4, so the GetFactionName function is working, but it’s being called too late.

Can you spot anything wrong, or have any ideas?

MySQL queries will always be slower than lua, you will have to use callback functions. So you call a function after the query is completed, and then you can use the data properly.

Like in this case, as a raw example, you’d have to make the concommand point to GetFactionName, and call Debug_GFI from the function GetFactionName.

You should look at the mysqloo thread a bit more in detail.

Wrong, it depends on how fast it can query it to the server and phpmyadmin.

Edited
Actually after reading your post are you connected to the mysql server

That’s not obviously the issue. As you can see the output is being printed correctly, the issue is the delay what mysql queries have.

What the fuck, how is phpmyadmin in any fucking way related?

Wrong again, that’s lua printing out the information not the mysql.

Dipsh…, phpmyadmin is where you send querys too, go learn lua and mysql and english, someone hasn’t been to school yet.

You’re so fucking stupid that you’re really pissing me off, he even stated that it’s working.

phpMyAdmin is a software to have easy access to the mysql server, it doesn’t handle the requests.

And as you can see, TestPls is being printed, and it is not in the lua.

Actually you’re the stupid one that’s him inputting gfi TestPls and it printing to the console.

Do you actually see TestPls on the script somewhere?

Try this


function GetFactionName(factionID, callback)
	local query1 = db:query("SELECT FactionName FROM gfactions_factionlist WHERE FactionID = '"..factionID.."'")
	query1.onSuccess = callback
	query1.onError = function(Q,E) print("Error Loading Faction") print(E) end
	query1:start()
end

function Debug_GFI( ply, cmd, args )
	local fID = args[1]
	GetFactionName(tonumber(fID),function(q)
		print("Debug_GFI")
		local info = q:getData()["FactionName"]
		print(info)
		ply:ChatPrint(info)
	end)
end
concommand.Add("gfi", Debug_GFI)

EDIT: @NinjaS: Why do you always insist on helping people with things you know nothing about?

That worked perfectly with a little modification.


local info = q:getData()["FactionName"]

had to be


local info = q:getData()[1]["FactionName"]

because for some reason it’s an extra step up in the table. You are awesome my friend.

And NinjaS, you’re completely wrong. I have a team entry already made in the MySQL table, whose teamname is TestPls and team ID number is 4. So when I search for ID 4 using the gti 4 concommand, it searches the table for an entry with team ID 4 and returns the team name. I think you owe him an apology :stuck_out_tongue:

fyi this is because it’s the first result returned, so when you select multiple rows each one gets its own entry in the table (ie. q:getData()[2][“FactionName”] will be the 2nd row that matched the query)

Because of lazy dumb :downs: autistic people like you :v:

Where do you store your mysql tables then? up your ass?


(User was banned for this post ("Trolling (4 reports, hence longer ban)" - Hexxeh))

How about, a MySQL server?