1LoL1 Posted August 4, 2015 Share Posted August 4, 2015 Please can anyone change of module/s to dbConnect database = mysql_connect( "...", "...", "...", "accounts" ) if database then outputDebugString ('Connect') else outputDebugString ("Trouble") end function saveAccounts () local serial = getPlayerSerial ( source ) local money = getPlayerMoney ( source ) local q = mysql_query(database,"SELECT * FROM `accounts` WHERE `serial` = '".. serial .."'") if(mysql_num_rows(q) == 0) then mysql_query( database, "INSERT INTO accounts ( `serial` , money ) VALUES ( '" .. serial .. "', " .. money .. " )" ) else res = mysql_query ( database, "UPDATE `accounts` SET x = money = ".. money .." WHERE `serial` = '"..serial.."'") end end function loadAccounts () local serial = getPlayerSerial ( source ) local result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `serial` = '"..serial.."'") if result then while true do local row = mysql_fetch_assoc(result) if not row then break end setPlayerMoney ( source, row.money ) break end end end addEventHandler ( "onPlayerJoin", getRootElement(), loadAccounts ) addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts ) Link to comment
GTX Posted August 4, 2015 Share Posted August 4, 2015 db_name = "..." host = "..." user = "..." password = "..." database = dbConnect( "mysql", "dbname="..db_name..";host="..host, user, password ) if database then outputDebugString ('Connect') else outputDebugString ("Trouble") end function saveAccounts () local serial = getPlayerSerial ( source ) local money = getPlayerMoney ( source ) local q = dbQuery(database,"SELECT * FROM accounts WHERE serial = ?", serial) local poll, rows = dbPoll(q, -1) if(rows == 0) then dbExec( database, "INSERT INTO accounts ( serial , money ) VALUES ( ?, ?)", serial, money ) else dbExec ( database, "UPDATE accounts SET money = ? WHERE serial = ?", money, serial) end end function loadAccounts () local serial = getPlayerSerial ( source ) local result = dbQuery ( database ,"SELECT * FROM accounts WHERE serial = ?", serial) local poll, rows = dbPoll(result, -1) if rows == 1 then setPlayerMoney ( source, poll[1]["money"] ) end end addEventHandler ( "onPlayerJoin", getRootElement(), loadAccounts ) addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts ) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now