Hey guys. I’m trying to get mysqloo working with this gamemode, but I can’t find a way to make these queries actually…well…query. I know mysqloo is working because I made a function in init.lua that created the required tables and columns, but the gamemode just won’t save/load player data. How would I set up mysqloo to query from multiple functions?? I’m new to SQL stuff so I’m trying my hardest.
mysqloo code to connect:
include("options.lua") include("obj_player_extend.lua") include("admin_shd.lua") include("admin_sv.lua") include("commands.lua") include("dice.lua") include("options_sv.lua") include("purchases_shd.lua") include("purchases_sv.lua") require ("mysqloo") local db = mysqloo.connect(MYSQL_DATABASE_HOST, MYSQL_DATABASE_USERNAME, MYSQL_DATABASE_PASSWORD, MYSQL_DATABASE_NAME, MYSQL_DATABASE_PORT) db:Connect() function db:onConnected() print("[CCGM] Database has been connected") end
What I’m trying to get working. All these functions that have sql queries. How to make connection without connecting to server in each function??
function GetSQLPid(self) local q = db.Query("SELECT player_id FROM zs_players WHERE steam_id='"..self:SteamID().."'") if not q then return end local pid for id,row in pairs(q) do pid = tonumber(row['player_id']) end return pid end function CCGM_PlayerDisconnected(user) local q = db:query("SELECT player_id FROM zs_players WHERE steam_id='"..user:SteamID().."'") if q then for id,row in pairs(q) do local pid = tonumber(row['player_id']) db.onConnected = function() local q = db:query("UPDATE zs_players SET last_connect='"..os.date("%Y-%m-%d %H:%M:%S").."' WHERE player_id='"..pid.."'") q:start() end end end end hook.Add("PlayerDisconnected", "CCGM Player Disconnect", CCGM_PlayerDisconnected) function HasLevelInformation(user) --return file.Exists("ccgm/zombiesurvival/info/"..string.gsub(user:SteamID(),":","_")..".txt") local query = db:query("SELECT steam_id FROM zs_players WHERE steam_id='"..user:SteamID().."'") if query then for id,row in pairs(query) do if row['steam_id']==user:SteamID() then return true end end end return false end
Edit: The Code to connect to the DB in the example code is in options_sv.lua as you see it is linked.