Jump to content

[OK] Insert a TAB to a Mysql DB


Recommended Posts

Posted (edited)

Hi all,

I'm trying to save "lastSeen" in a mysql table called "DM".

I got some issue.

  
rootElement = getRootElement() 
  
... 
  
function realTime() 
    local lastSeen = getRealTime() -- It returns a tab 
end 
addEventHandler("onPlayerQuit",rootElement,realTime) 
  
-- Later in my code 
dbExec(connect,"INSERT INTO DM (lastSeen,timePlayed,cash,moneyUse,moneyWon,timeJoin,toPlayer) VALUES ('"..time..":""','0','0','0','0','0','"..account.."')") 
  
... 
  

It's not working :-/ How to save an answer from getRealTime() in my DB ?

Edited by Guest
Posted (edited)

Maybe like this?

  
local hours,minutes  
rootElement = getRootElement() 
  
... 
  
function realTime() 
    local time = getRealTime() 
    hours = time.hour 
    minutes = time.minute 
end 
addEventHandler("onPlayerQuit",rootElement,realTime) 
  
-- Later in my code 
dbExec(connect,"INSERT INTO DM (lastSeen,timePlayed,cash,moneyUse,moneyWon,timeJoin,toPlayer) VALUES ('"..hours..":"..minutes.."','0','0','0','0','0','"..account.."')") 
  
... 
  

Edited by Guest
Posted
Maybe like this?
  
  
rootElement = getRootElement() 
  
... 
  
function realTime() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
end 
addEventHandler("onPlayerQuit",rootElement,realTime) 
  
-- Later in my code 
dbExec(connect,"INSERT INTO DM (lastSeen,timePlayed,cash,moneyUse,moneyWon,timeJoin,toPlayer) VALUES ('"..hours..":"..minutes.."','0','0','0','0','0','"..account.."')") 
  
... 
  

That wouldn't work because variables hours and minutes are local in realTime function. You would have to make the realTime function return those values.

Posted (edited)

Ok thanks.

But now i try to set a variable with a string.

  
rootElement = getRootElement() 
  
------ Functions -------- 
-- Return the real time (TO BE TESTED) 
function realTime() 
    local time = getRealTime() 
    day = fromJSON(time.monthday) 
    month = fromJSON(time.month) 
    year = fromJSON(time.year + 100) 
    hours = fromJSON(time.hour) 
    minutes = fromJSON(time.minute) 
    lastSeen = "Lastseen : "..toString(day).."/"..toString(month).."/"..toString(year).." - "..toString(hours)..":"..toString(minutes).."" 
end 
addEventHandler("onResourceStart",rootElement,realTime) 
  
outputDebugString(lastSeen) 
  

It doesn't work :-/

Edited by Guest
Posted

Of course it will not work. onResourceStart (if we speak about current resource) runs AFTER everything outside it. So outputDebugString should be inside the realTime function.

Posted

Thanks for your help.

  
-- Return the real time 
function realTime() 
    local time = getRealTime() 
    local day = time.monthday 
    local month = time.month 
    local year = time.year +1900 
    local hours = time.hour +1 
    local minutes = time.minute +1 
    local lastSeen = "Lastseen : "..day.."/"..month.."/"..year.." - "..hours..":"..minutes.."" 
    return lastSeen 
end 
addEvent("onPlayerQuiUpdateLastSeen",true) 
addEventHandler("onPlayerQuitUpdateLastSeen",rootElement,realTime) 
  

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...