MySqloo and global variables?

Hey everyone!
I have this Mysqloo function which fetches the SQL query result.



local test = ""
function doQuery(query, fetchK)
	
		local sql_connection = mysqloo.connect(sql_address, sql_user, sql_pass, sql_db, 3306)
		function sql_connection:onConnected()
			
			local qDB = self:query(query)
			local qfetch = fetchK
			
			print("connection succeeed")
			function qDB:onSuccess(data)
				local s = {}
				for k,v in pairs(data) do
					--PrintTable(v)
					test = tostring(v[fetchK])
					
					print(test) -- This works
				end
print(test) -- This doesnt work D:
			end
			
			function qDB:onError(err)
				print("query failed")
				print(err)
			end
			qDB:start()
		end
			function sql_connection:onConnectionFailed( err )
				print("failed connection!")
				print(err)
				PrintMessage(HUD_PRINTTALK, "ALERT! Could not connect to the SQL databases :c")
			end
				sql_connection:connect()
				
				
				print(test) -- Again doesnt work
			
	end


How best do I go about getting the result out of the query onSuccess function? Would it be a callback? I need to get the result back into ENT:Use. (Is that a bad thing to do?)
Any ideas?
Thanks!

What you should do is add another argument to doQuery for a callback function and call that function in onSuccess with the data, so that in your ENT:Use function, you can do



doQuery("SELECT blah FROM blah", "?", function(data)
 
-- Your stuff

end)

Why do lua tags always fuck up?

How do I add the callback to the function? Thanks!


function doQuery(query, fetchK, callback)


function qDB:onSuccess(data) callback(data) end

Awesome, thanks!
Is it acceptable to add a timer to give the server time to do the query while retrieving the callback value?
Thanks!

Oh god, please excuse my retarded response. Just add it to the callback function… Jesus. Sorry. Thanks man.