Hello, I'm having some problems with the Mysqloo,
One is a error through out the Server and Client.
[code]
((null))Error: Trying to network (receive) unacceptable type ((null))Disconnect: Server shutting down.
Disconnect: Server shutting down.
[/code]
Heres my Database Code, and it connects perfectly. i get in console the connection hasn't failed.
[code]
DB_HOST = "ip"
DB_USER = "user"
DB_PASS = "pass"
DB_PORT = port
DB_NAME = "name"
hook.Add("Initialize", "DB:Init", function()
require("mysqloo")
if(mysqloo) then
Database = mysqloo.connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT)
function Database:onConnected()
print("=============================================================================")
hook.Call("DatabaseConnected", GAMEMODE, Database)
print("Mysql: Database Connected!!!")
print("Mysql: Connected to IP: '"..DB_HOST.."',\n Username: '"..DB_USER.."',\n Password: '"..DB_PASS.."',\n DatabaseName: '"..DB_NAME.."',\n Port: '"..DB_PORT.."'")
print("=============================================================================")
ERR = nil
end
function Database:onConnectionFailed( err )
print("=============================================================================")
hook.Call("DatabaseFailed", GAMEMODE, Database, err)
print("Database Failed!!!!")
print("Mysql: Connected to IP: '"..DB_HOST.."',\n Username: '"..DB_USER.."',\n Password: '"..DB_PASS.."',\n DatabaseName: '"..DB_NAME.."',\n Port: '"..DB_PORT.."'")
print("=============================================================================")
end
Database:connect()
end
end)
hook.Add("DatabaseConnected", "Database:Connected", function()
MsgC( Color(0, 255, 0, 255), "["..GAMEMODE.Name.."] Database Connected\n" )
end)
hook.Add("DatabaseConnectionFailed", "Database:Failed", function(_db, _err)
MsgC( Color(255, 0, 0, 255), "["..GAMEMODE.Name.."] Database Connection Failed!\n" )
MsgC( Color(255, 0, 0, 255), "["..GAMEMODE.Name.."] Stopping Server Due to the Error:".._err.."\n" )
RunConsoleCommand("disconnect")
end)
hook.Add("PlayerInitialSpawn", "Setup_Player", function(ply)
DBInit(ply)
end)
hook.Add("PlayerSpawn", "Debug_player", function(ply)
DBLoad(ply)
end)
function DBInit(ply)
local query1 = Database:query("SELECT * FROM player_info WHERE unique_id = '"..ply:ShortSteamID().."'")
query1.onSuccess = function(q)
if(not DBCheck(q)) then
local query2 = Database:query("INSERT INTO player_info(unique_id, money, level, xp) VALUES ("..ply:ShortSteamID()..", '50000', '1', '0')")
query2.onSuccess = function(q) ply:ChatPrint("Mysql: Created your player data!") dev_printtable(q) end
query2.onError = function(q,err) ply:ChatPrint("Mysql: Creation of your player data has failed!") ply:ChatPrint("Error: ".. err)end
query2:start()
else
ply:ChatPrint("Account Already Created") dev_printtable(q)
end
end
query1.onError = function(q,e) ply:Kick("Mysql: Checking your account failed!") end
query1:start()
end
function DBLoad(ply)
ply:ChatPrint("Loading Data...")
local Query1 = Database:query("SELECT unique_id FROM player_info WHERE unique_id = '"..ply:ShortSteamID().."'")
ply:SetNWString("unique_id", Query1)
local Query2 = Database:query("SELECT money FROM player_info WHERE unique_id = '"..ply:ShortSteamID().."'")
ply:SetNWInt("money", Query2)
local Query3 = Database:query("SELECT level FROM player_info WHERE unique_id = '"..ply:ShortSteamID().."'")
ply:SetNWInt("level", Query3)
local Query4 = Database:query("SELECT xp FROM player_info WHERE unique_id = '"..ply:ShortSteamID().."'")
ply:SetNWInt("xp", Query4)
end
function dev_printtable(query)
PrintTable("TABLE: "..query:getData())
end
function DBCheck(query)
local playerInfo = query:getData()
if playerInfo[1] ~= nil then
return true
else
return false
end
end
[/code]
On the plus note, i've double checked the code to see, if i caused any lua errors which i didn't.
And my second question how would i get data out of the Data Table, else have i been doing it correctly. Where to check is in function 'DBLoad'.
Sorry, you need to Log In to post a reply to this thread.