[MYSQL/LUA] Why?!

function getMysqlData ( source, data )
    MySQL.Async.fetchAll("SELECT `"..data.."` FROM `users` WHERE `name`='"..GetPlayerName(source).."'", {}, 
    function (result) --funcion in function
        endresul = result[1][data]
        return endresul
    end)
    return endresul 
end


function newJobID ( source )
print(getMysqlData(source, "job"))
end
RegisterCommand("newjob", newJobID, false)```


Why i get nil?

Hey,

You are using async version of MySQL query. Use

local result = MySQL.Sync.fetchAll("SELECT " ..data.." FROM `users` WHERE `name`='"..GetPlayerName(source).."'", {})
if result[1]and result[1][data]then return result[1][data]end
return nil

You can also use promise:new but that’s just over complicating things

Why u return nil @ the end?

Because if the condition result[1]and result[1][data] is false nothing will be returned