Jump to content

[HELP] MySQL


1LoL1

Recommended Posts

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
  
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

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...