• MySqloo query not working??
    8 replies, posted
Hey there, Heres my code, description of problem after: [CODE]function GetData( ply ) local queryinf = [[ SELECT * FROM 'serverdata' WHERE uniqueid = '%s' ]] queryinf = string.format(queryinf, ply:UniqueID()) q = db:query(queryinf) function q:onSuccess(data) local row = data[1] local money = row.money MsgN ("Success:"..money) end end[/CODE] the error is [CODE][ERROR] gamemodes/gsbasewars/gamemode/mysql.lua:33: attempt to index global 'q' (a nil value) 1. GetData - gamemodes/gsbasewars/gamemode/mysql.lua:33 2. v - gamemodes/gsbasewars/gamemode/init.lua:44 3. unknown - lua/includes/modules/hook.lua:84[/CODE] The GetData function is ran on a players initial spawn. Line 33 is q:OnSuccess
Did you define "db"?
[QUOTE=Strideynet;46959623]Hey there, Heres my code, description of problem after: [CODE]function GetData( ply ) local queryinf = [[ SELECT * FROM 'serverdata' WHERE uniqueid = '%s' ]] queryinf = string.format(queryinf, ply:UniqueID()) q = db:query(queryinf) function q:onSuccess(data) local row = data[1] local money = row.money MsgN ("Success:"..money) end end[/CODE] the error is [CODE][ERROR] gamemodes/gsbasewars/gamemode/mysql.lua:33: attempt to index global 'q' (a nil value) 1. GetData - gamemodes/gsbasewars/gamemode/mysql.lua:33 2. v - gamemodes/gsbasewars/gamemode/init.lua:44 3. unknown - lua/includes/modules/hook.lua:84[/CODE] The GetData function is ran on a players initial spawn. Line 33 is q:OnSuccess[/QUOTE] If you actually paid for the script then contact the author of it.
[QUOTE=Fillipuster;46959872]Did you define "db"?[/QUOTE] This seems to happen to me too when Garry's Lua Autorefresh kicks in with the Mysqloo module - then eventually leads to a server crash. Frankly because I dont know how to preserve variables betwen reloads of the Lua
[QUOTE=SeveredSkull;46969824] Frankly because I dont know how to preserve variables betwen reloads of the Lua[/QUOTE] global variable = variable or value
[QUOTE=SeveredSkull;46969824]This seems to happen to me too when Garry's Lua Autorefresh kicks in with the Mysqloo module - then eventually leads to a server crash. Frankly because I dont know how to preserve variables betwen reloads of the Lua[/QUOTE] If you're using a wrapper, or a global accessor, the easiest method is: DATABASE = DATABASE || { }; or blah = blah || default; so the first time around when DATABASE or blah is nil / unset, it'll use the default value which then gets populated by your script. On auto-refresh, the value exists so it uses itself. This will only work on globals, but for a database wrapper keeping it global in the server realm isn't a bad idea. [QUOTE=StonedPenguin;46969923]global variable = variable or value[/QUOTE] -ninja'd-
[QUOTE=StonedPenguin;46969923]global variable = variable or value[/QUOTE] [QUOTE=Acecool;46969925]If you're using a wrapper, or a global accessor, the easiest method is: DATABASE = DATABASE || { }; or blah = blah || default; so the first time around when DATABASE or blah is nil / unset, it'll use the default value which then gets populated by your script. On auto-refresh, the value exists so it uses itself. This will only work on globals, but for a database wrapper keeping it global in the server realm isn't a bad idea. -ninja'd-[/QUOTE] Thanks Mates! Didnt realize it was that simple.
As for the OP, db:query will return nil if the database object isn't connected.
Ah okay. I restructured my code to execute the query when the database connects thanks. [editline]20th January 2015[/editline] [QUOTE=AIX-Who;46959958]If you actually paid for the script then contact the author of it.[/QUOTE] I coded this myself....
Sorry, you need to Log In to post a reply to this thread.