Jump to content

Help with the sql


Recommended Posts

I have a server side script, but when i load it up at the server doesnt give any errors, but still not work please someone can help me about it there is my script: And yes i am new in the sql world xD

  
  
local dbConnection = dbConnect( "mysql", "dbname=mta-szerver;host=localhost","root" "" ) 
  
if dbConnection then 
    OutputConsole ( "The database has failed to connect")  
else 
    OutputConsole ( "Database has been connected") 
end 
  
  
  
function dbConnectionQuery(player, block, var) 
    if (player and isElement(player)) then 
        local query = dbQuery(dbConnection, "UPDATE 'accountdata' SET '" ..block.."' = '" ..var.."' WHERE Username ='" ..getPlayerName(player).."'"); 
         
        if query then  
            return true 
             
        end 
        outputDebugString("Error"..query.."|"); 
     
 end 
 end 
  
 function dbConnectionGetQuery(player, block) 
 if (player and isElement(player)) then  
    local query = dbQuery(dbConnection,"SELECT ?? FROM accountdata WHERE Username = ?",block, getPlayerName(player)) 
    local result = dbPoll(query, -1); 
     
    if (result == nil ) then 
        dbFree(query) 
        return false; 
    else 
        return result; 
    end 
end 
end 
addCommandHandler("cmd", function(player) 
    local money = dbConnectGetQuery(player, "money"); 
     
    if money then 
        outputChatBox("Valami"..tonumber(money).."|",player); 
    end 
    dbConnectSetQuery(player, "Money", 100); 
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...