Can we return a value getted from Async ? (FXServer)
Ex :
function getPlayerMoney(player)
MySQL.Async.fetchAll("SELECT money FROM users WHERE identifier = @identifier", { ['@identifier'] = player }, function(result)
return result[1].money
end)
end
Can we escape from the async callback and keep the value ?
Async on FxServer make my server crash randomly : https://pastebin.com/Zib2hdwr
look at : SELECT banned FROM user_ipblacklist WHERE ip = @ip AND banned = 17fd3e11b4000-7fd3e23b5000 rwxp 00000000 00:00 0
Can you fix this bug please ?
Thanx
function gotMoneyExample()
getPlayerMoney(player, function(result)
local moneyFromDB = result
-- Do whatever else you need with the result here, or send the result to a global variable instead.
end)
end
function getPlayerMoney(player, callback)
MySQL.Async.fetchAll("SELECT money FROM users WHERE identifier = @identifier", { ['@identifier'] = player }, function(result)
callback(result[1].money)
end)
end
HELP ME PLEASE I installed the EssentialMode base The server is hosted not on localhost
.
But now I have other problems
When I put /admin gives me an error: https://gyazo.com/aedcbd5380292b7897169415bcdf170e
I have done some tests, the more you have of âSELECTâ queries executed, the more your server risk of crash, if you put a request âSELECTâ to check if the person is banned when it connect, That your crash server frequently.
(I Have the last version and is same on the old version)
Which test ? We have select for the ban thing, and we got 48h uptime without crash easily. Please stop staying thing without proof / evidence / reproduction scenario, with this i just can say : Mokay ? But cannot done anything neither helping you, if this is really a failure.
Sorry I do not want to look nasty but itâs true, my server is full everytime 32/32, i can make tests properly, without checking ban, the server crash two three times a day, with the script for checking ban, the server crash two three times per hour !
This is my script for checking ban : https://pastebin.com/3briTQAg I donât see something wrong in my script âŚ
Hmmm⌠Yeah but no, If I get ALL bans at the server start with âonMySQLReadyâ and put them in table (https://pastebin.com/b2GLVyM2 if someone want), the server donât crash, he crash everytime only when I use SELECT for every connection to the server.
Error running system event handling function for resource banscript: citizen:/scripting/lua/scheduler.lua:39: Failed to
execute thread: sv_ban.lua:13: attempt to call a nil value (field 'getUserRankQuery')
stack traceback:
sv_ban.lua:13: in function 'getPlayerRank'
sv_ban.lua:7: in upvalue 'handler'
citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
with this code
local db = {}
AddEventHandler("chatMessage", function(source, name, message)
local cm = stringsplit(message, " " , " ")
if cm[1] == "/test" then
getPlayerRank(source)
end
end)
--[[ Main Functions ]]--
function getPlayerRank(id)
db.getUserRankQuery(id, function(result)
print(#result)
end)
end
--]]
--[[ MySQL Callbacks ]]--
AddEventHandler("onMySQLReady", function()
db.getUserRankQuery = function(id, callback)
local ident = GetPlayerIdentifiers(id)[1]
MySQL.Async.fetchAll("SELECT * FROM admins WHERE identifer = @ident", {['@ident']=ident}, function(result)
callback(result)
end)
end
db.getUserBanQuery = function(id, callback)
local ident = GetPlayerIdentifiers(id)[1]
MySQL.Async.fetchAll("SELECT * FROM bans WHERE identifier = @ident", {['@ident']=ident}, function(result)
callback(result[1])
end)
end
end)
I apologize if I did something wrong I just have never used mysql-async before.
Hi
When launching my server, to try the example.lua script in the mysql-async folder, I get this error
Started resource fivem-map-skater
Started map fivem-map-skater
Loaded MySqlConnector, Version=0.24.0.0, Culture=neutral, PublicKeyToken=null into ScriptDomain_848326817
Loaded System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 into ScriptDomain_848326817
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT @parameters {@parameters=1}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT @parameters {@parameters=string}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT "hello1" as world {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(4) {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(1) {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(2) {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(5) {=}": Unable to connect to any of the specified MySQL hosts.
Error running system event handling function for resource mysql-async: citizen:/scripting/lua/scheduler.lua:39: Failed to execute thread: example.lua:59: attempt to index a nil value
stack traceback:
example.lua:59: in upvalue 'handler'
citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
[C]: in function 'coroutine.resume'
citizen:/scripting/lua/scheduler.lua:33: in field 'CreateThreadNow'
citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT NOW() as world {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(3) {=}": Unable to connect to any of the specified MySQL hosts.
hitch warning: frame time of 4701 milliseconds