• MySQL Module Issues
    7 replies, posted
I am getting the following error when I try to use MySQL: Gamemode/gamemode/init.lua:77: attempt to index local 'uid' (a boolean value) My lua: [lua]--Lines 75 - 93 function steamcheck(name, pass, steam, ip) local uid = db(steam) if uid[1] and uid[1][2] then local allowed = dba(steam,"2") if allowed[1] and allowed[1][2] then updatedb(name,steam,ip) return true else return {false, "The server is currently for admins only."} end else addtodb(name,steam,ip) return {false, "You have been added to the database. Please reconnect to join the server."} end local close = mysql.disconnect(db); if close then end return end hook.Add("PlayerPasswordAuth", "Example", steamcheck) -- DB function function db(steam) local db = mysql.connect('HOST', 'USER', 'PASS', 'DB Name') return mysql.query(db, "SELECT * FROM rave1 WHERE steam = '" .. steam .. "'"); end[/lua]
Simply reading the error tells you the problem. It seems your db function is returning either true or (most probably) false, maybe because of a failed request? I don't really know that library. :smile: Actually it's either that or uid[1] is a boolean value and you can't index it. What should db return usually? Anyway you should try using print() in several parts of your script to debug, it's very helpful.
It worked up until earlier, and all I changed was the DB information. (changed to a better host, was using db4free [editline]10:53PM[/editline] Ok, I created some test code and it causes the server to appear crashed for about 15 seconds then come back with nothing. [lua]function sqlCheck(ply) local db, error = mysql.connect(Connection Information goes here) if (db == 0) then ply.ConCommand("say " .. tostring(error) .. "\n") return end print("connection opened - " .. db .. "!\n"); test, isok, error = mysql.query(db, "SELECT * FROM rave1 WHERE steam = '" .. ply:SteamID() .. "'"); if (test) then ply:ConCommand("say Yeah!") end if (!isok) then ply.ConCommand("say " .. tostring(error) .. "\n"); end local succ, error = mysql.disconnect(db) if (not succ) then ply.ConCommand("say " .. error ); end end concommand.Add("check",sqlCheck)[/lua] [editline]10:55PM[/editline] Ok, obvious stupidity is obvious, fixed and testing again [editline]11:00PM[/editline] Ok, so now its giving me the error (using the above): Unknown MySQL server host 'derlynx.ipowermysql.com' (11004) Checking another url that I have here [editline]11:09PM[/editline] Now the error is Can't connect to MySQL server on 'custsql-ipw16.eigbox.net' (10065) This is really confusing the hell outta me, because the SQL is accessed by my website fine
Your new server does not have remote access, ask your host if they can turn it on for you. Some hosts won't do this though. It's probably accessed by your website find because your database is probably local to the site, whereas a game server is not unless it's a dedicated server box.
Does anyone know of a host that allows this? I have talked to 2 (ipower.com and bluehost.com) and they both disallow this.
hastyhost.com allow it, not automatically but if you have a good enough reason they will open port 3306
[QUOTE=talasdw;18548288]Does anyone know of a host that allows this? I have talked to 2 (ipower.com and bluehost.com) and they both disallow this.[/QUOTE] Bluehost.com does allow it, I host with them and get along fine.
[QUOTE=yakahughes;18609334]Bluehost.com does allow it, I host with them and get along fine.[/QUOTE] Hmm. Will have to recheck with them (have an account on there expiring in about a month). There a bit expensive though, get cheaper for more through my game server host.
Sorry, you need to Log In to post a reply to this thread.