Pointshop MySQL

Is there anything out there to convert from pdata to mysql?

Wish to change to MySQL but don’t want to reset every players points/items/etc.

When the player joins, check if he got any valid points in his pdata. If he does, update the mysql with these points, then remove the pdata.

There’s currently no way to convert all pdata and dump it in some file.

[lua]require ( “mysqloo” )

CheckDB = {}
CheckDB.dbConnected = false

function connectDB()
db=mysqloo.connect("…") – set up mysql connection

db.onConnected = function()	
	CheckDB.dbConnected = true -- db is connected

db.onConnectionFailed = function(self, err)
	CheckDB.dbConnected = false -- db isn't connected
	print("Error Occured: ", err) -- print error in console
	timer.Simple(60, function()
		db:connect() -- try to connect again in 60 seconds if failed
db:connect() -- connect to db

hook.Add(“Initialize”, “PointshopMySQL”, connectDB) – connectDB on Initialize hook

– Taken from http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb25c.html
function checkQuery(query)
local playerInfo = query:getData()
if playerInfo[1] ~= nil then
return true
return false

– Check pdata for user to find points and items
– Send them to the MySQL database to store them
– then remove the old pdata
function checkPD(ply)
local checkquery = db:query(“SELECT * FROM pointshop_data WHERE uniqueid = '” … ply:uniqueID() … “’”) – Check if player exists
checkquery.onSuccess = function(q) – if successful
if not checkQuery(q) then – if query has no results (i.e the player hasn’t been converted)

		points = ply:GetPData('PS_Points', 0) -- Get pdata for PS_Points (0 by default)
		items = util.JSONToTable(ply:GetPData('PS_Items', '{}')) -- Get pdata for PS_Points (empty by default)
		-- Insert the uniqueID, points and items into the table if it's not been converted already
		local inputquery = db:query("INSERT INTO pointshop_data (uniqueid, points, items) VALUES ('" .. ply:uniqueID() .. "',".. points .. ",'".. items .. "')")
		inputquery.onSuccess = function(q) 
			print("Converted a player to MySQL") 
			ply:RemovePData('PS_Points') -- remove PS_Points pdata
			ply:RemovePData('PS_Items') -- remove PS_Items pdata
		inputquery.onError = function(q,e) print("Something went wrong with the INSERT") end -- print console msg if error
		inputquery:start() -- start query
	else -- if query has a result (i.e player has been converted)
		print("User has already been converted")
checkquery.onError = function(q,e) print("Something went wrong with the SELECT") end -- print console msg if error
checkquery:start() -- start query

hook.Add(“PlayerInitialSpawn”, “CheckPDataAndUpdateMySQL”, checkPD) – add function to Player Init Spawn hook[/lua]

would that do the job?