Lua Hook Error On Player Join

Hi, i’m editing the mod UTime (stores playtime of players on the server) to use a SQL database, so both my server have the same time for each player and i got the sql part working but whenever somebody joins I get this error in my server console:

ERROR: Hook ‘PlayerHasJoined’ Failed: autorun/sv_utime.lua:20: Error: Invalid Connection

Removing Hook ‘PlayerHasJoined’

The hook is meant to start a function which loads that players acount when they join, or create a new one. This is the hook itself: hook.Add( “PlayerInitialSpawn”, “PlayerHasJoined”, LoadAccount )

Thanks for any help.

We will need the source of LoadAccount in order to ably assist you.

Ok im not entirly sure i know what you mean but im guessing you want the function itself (Im not sure how you put it in a code box):

function LoadAccount( ply )
local steamid = ply:SteamID()
local nick = ply:Nick()
local time = 0
local txt = “”

local table, success, error = mysql.query(db, "SELECT time FROM sasserver WHERE SteamID = '"..tostring(steamid).."'");
if ( !success ) then Error( "Error: " ..tostring(error).. "

" ) end

if ( table ) then
	time = table[1]
	txt = "Loaded SAS Profile!"
	time = 0
	mysql.query(db, "INSERT INTO sasserver ( SteamID, nick, time ) VALUES ('"..tostring(steamid).."', '"..tostring(nick).."', "..time.." );");
	txt = "Creating SAS Profile!"
ply:SetUTime( time )
ply:SetUTimeStart( CurTime() )

hook.Add( “PlayerInitialSpawn”, “PlayerHasJoined”, LoadAccount )

wel, we neede to hole lua file but, the error says connection failed, so i tihnk its something whit the MySQL :slight_smile:


 or [lua] tags

You need to connect to the mysql server

require( “mysql” )

local db, error = mysql.connect(“localhost”, “username”, “password”, “database”)
if (db == 0) then Msg(error … "

I presume you have Mysql right, the module?

Yes i do, anyway thanks for trying to help but i fixed it now… i dont know why but in the:
mysql.query(db, blahblah)
the ‘db’ needs to be the same db as:
local db, error = mysql.connect(“localhost”, “username”, “password”, “database”)