Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require( "mysqloo" )
- local auth = {
- hostname = '37.122.209.16',
- username = 'AC2',
- password = 'Rockslol',
- database = 'scoreboardhudftwchudlol_elevel',
- port = 3306
- }
- local db = mysqloo.connect( auth.hostname, auth.username, auth.password, auth.database, auth.port )
- db:connect()
- function db:onConnected()
- local q = self:query( "CREATE TABLE IF NOT EXISTS `elevel` ( `ID` char(64) NOT NULL, `JSONData` text NOT NULL, PRIMARY KEY (`ID`) )" )
- q:start()
- MsgC( Color( 255, 50, 50 ), "[*]", Color( 255, 255, 255 ), "Serverlog: ", Color( 255, 255, 255 ), "Connection to database succesful\n" )
- end
- function db:onConnectionFailed( err )
- MsgC( Color( 255, 255, 255 ), "Serverlog: ", Color( 255, 255, 255 ), "Connection to database failed\n" )
- MsgC( Color( 255, 255, 255 ), "Serverlog: ", Color( 255, 255, 255 ), "Error: "..err.."\n" )
- end
- function EL_loadInfo( steamID, callback )
- local query = db:query( "SELECT * FROM elevel WHERE ID = '" .. steamID .."'" )
- function query:onSuccess( data )
- if table.Count( data ) == 0 then
- callback( {}, 0 )
- return
- end
- callback( util.JSONToTable( data[ 1 ].JSONData ) )
- end
- function query:onError( err )
- print( "An error occured while executing the query: " .. err )
- end
- query:start()
- end
- function EL_saveInfo( steamID, inventory )
- local query = db:query( "SELECT * FROM elevel WHERE ID = '" ..steamID.."'" )
- function query:onSuccess( data )
- if data && data[ 1 ] then
- local updateQuery = db:query( "UPDATE elevel SET JSONData = '" ..inventory.."' WHERE ID = '" ..steamID.. "'" )
- function updateQuery:onError( err, sql )
- print("An error occured while executing the query: " .. err)
- end
- updateQuery:start() -- update user information, because he exists.
- else
- local insertQuery = db:query( "INSERT INTO elevel (`ID`,`JSONData`) VALUES('"..steamID.."' ,'"..inventory.."')" )
- function insertQuery:onError( err, sql )
- print("An error occured while executing the query: " .. err)
- end
- insertQuery:start() -- insert user if he doesn't exist.
- end
- end
- function query:onError( err, sql )
- print("An error occured while executing the query: " .. err)
- end
- query:start() -- select user from the database
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement