Jump to content

User panel DB on web


papam77

Recommended Posts

Hey, i want saving user panel db to web. How can do it ?

------------------------------------------ 
-- Load & Save Data 
------------------------------------------ 
function loadPlayerData (player,datatype) 
  local playerSerial = getPlayerSerial (player) 
  if (playerSerial) then 
    local root = xmlLoadFile ("DataBase.xml") 
    if (root) then 
      local usersNode = xmlFindChild (root,"user",0) 
      if (usersNode) then 
        local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0) 
        if not (playerRootNode == false) then 
          local playerData = xmlNodeGetAttribute (playerRootNode,datatype) 
          if (playerData) then 
            xmlUnloadFile (root) 
            --outputDebugString("---- LoadD: "..getPlayerName(player).."   ,   "..datatype.."   ,   "..playerData) 
            return playerData 
          else 
            xmlNodeSetAttribute (playerRootNode,datatype,0) 
            xmlSaveFile (root) 
            xmlUnloadFile (root) 
            --outputDebugString("---- LoadD: "..getPlayerName(player).."   ,   "..datatype.."   ,   0") 
            return 0         
          end 
        else 
          local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial) 
          xmlNodeSetAttribute (playerRootNode,datatype,0) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          --outputDebugString("---- LoadD: "..getPlayerName(player).."   ,   "..datatype.."   ,   0") 
          return 0  
        end 
      end 
    end 
  end 
end 
  
function savePlayerData (player,datatype,newvalue) 
  local playerSerial = getPlayerSerial (player) 
  if (playerSerial) then 
    local root = xmlLoadFile ("DataBase.xml") 
    if (root) then 
      local usersNode = xmlFindChild (root,"user",0) 
      if (usersNode) then 
        local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. playerSerial,0) 
        if not (playerRootNode == false) then 
          local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          --outputDebugString("---- SaveD: "..getPlayerName(player).."   ,   "..datatype.."   ,   "..newvalue) 
          return newNodeValue 
        else 
          local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. playerSerial) 
          local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          --outputDebugString("---- SaveD: "..getPlayerName(player).."   ,   "..datatype.."   ,   "..newvalue) 
          return newNodeValue 
        end 
      end 
    end 
  end 
end 

to ----> http://kfc-gaming.eu/DataBase.xml

Link to comment
Learn Lua :P .?

Too hard for my brain :D

if learning lua is to hard for your brain, start at the highest point and jump down!

With saying that I mean, you want to learn lua and also make something usefull for your self, so... Create a script that saves the user information into a database, just keep it simple first. Save the serial of an user in a table, you can use the function dbConnect and executeSQLQuery for that.

First thing to do is create a dbconnection

  
dbConnect( "sqlite", "file.db" ) -- string databaseType, string host  
  

after you got the connection to your database, you can start selecting and inserting stuff. Before you can do this, you need to have alitle knowledge about SQL. but the functions you're going to use are;

  
create table 
insert 
select 
  

to help you into the right direction:

  
local dbType = "sqlite" 
local dbFile = "mtaServer.db" 
  
addEventHandler("onResourceStart", root, 
    function () 
        local create = executeSQLQuery("CREATE TABLE IF NOT EXISTS `players` (`serial` TEXT)") 
        if ( create ) then 
            outputChatBox("Table created!") 
        end 
    end 
) 
  
addCommandHandler("saveSerial", 
    function ( source ) 
        local serial = getPlayerSerial( source ) 
        local insert = executeSQLQuery("INSERT INTO players(serial) VALUES(?)", serial ) 
        if ( insert ) then 
            outputChatBox("Serial saved into the db!") 
        end 
    end 
) 
  

(haven't tested it)

Link to comment

A joining to DB file is this code ?

local function connect( ) 
    -- retrieve the settings 
    local server = get( "server" ) or "localhost" 
    local user = get( "user" ) or "root" 
    local password = get( "password" ) or "" 
    local db = get( "database" ) or "mta" 
    local port = get( "port" ) or 3306 
    local socket = get( "socket" ) or nil 

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