MySQL Problems

This is my code


 if (!SERVER) then return; end;

 require ("mysqloo")                // Include the modules
 require ("glon")



local DATABASE_HOST = "******.net"  
local DATABASE_PORT = 3306               
local DATABASE_NAME = "*******"    
local DATABASE_USERNAME = "*********"      
local DATABASE_PASSWORD = "*****************************"        
local CONNECT = false;


function file.AppendLine(filename, addme)
	data = file.Read(filename, "DATA")
	if ( data ) then
		file.Write(filename, data .. "
" .. tostring(addme))
	else
		file.Write(filename, tostring(addme))
	end
end

function myLog(str, fn)
	if not fn then fn = "mysql.txt" end
	file.AppendLine(fn, "[Log: "..tostring(os.date()).."] "..str)
end

local function connectToDatabase2()
	INVENTORY_MYSQL = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
	INVENTORY_MYSQL.onConnected = function() CONNECT = true; myLog("Connected to Database."); checkTable2(INVENTORY_MYSQL); end
	INVENTORY_MYSQL.onConnectionFailed = function() myLog("Failed to connect to the database.") CONNECT = false;end
	INVENTORY_MYSQL:connect();
					myLog("loading from mysql tell me if you see this message5");
	MsgN("CONNECTED");
	//CONNECT = true;
end



connectToDatabase2();

function checkQuery2(query)
    local playerInfo = query:getData()
    if playerInfo[1] ~= nil then
		return true
    else
		return false
    end
end

function checkTable2(server)
	print("Create MYSQL Pdata.")
	local ii = ',';
	local str = '';
	for i = 1, 5 do
		str = str .. ' equipslot'..tostring(i)..' TEXT' .. ii;
	end
	for i = 1, 50 do
		if (i == 50) then ii = ''; end;
		str = str .. ' slot'..tostring(i)..' TEXT'..ii
	end
	local Qc  = server:query( "CREATE TABLE IF NOT EXISTS playerinventories ( steamid VARCHAR(255) NOT NULL PRIMARY KEY,"..str.. ");") 
	Qc.onError = function(Q,Err) print("Failed to Create Table: " .. Err) end
	Qc:start()
end

local meta = FindMetaTable("Player");
  
	function meta:GetPDataMYSQL( name, default, callback, args )
		if (!CONNECT) then return; end;
		if (!IsValid(self)) then return; end;
		name = Format( "%s[%s]", self:UniqueID(), name )
		local query1 = INVENTORY_MYSQL:query("SELECT value FROM playerinventories WHERE steamid = '" .. tostring(name) .. "'");// LIMIT 1");--"
		local val1 = nil;
		query1.onSuccess = 
		function(q)
			if (checkQuery2(q) == true)
			then
				//self:ChatPrint("Loading from MYSQL");
				val1 = q:getData();
				callback(val1, default, args, false);
			else
				//callback(sql.QueryValue( "SELECT value FROM playerpdata WHERE steamid = " .. SQLStr(name) .. " LIMIT 1" ), default, args, true);
			end
		end
		query1:start();
		return true;

	end

	function meta:LoadInventoryFromMYSQL()
		if (CONNECT) then
			if (!IsValid(self)) then return; end;

			local query1 = INVENTORY_MYSQL:query("SELECT * FROM playerinventories WHERE steamid = '" .. self:SteamID() .. "';")// LIMIT 1
			local val1 = nil;

			query1.onSuccess = function(q)
				if (checkQuery2(q) == true) then --yes we get here
					val1 = q:getData();
					for k, v in pairs(val1[1]) do self:ChatPrint(tostring(k).."    !"..tostring(v).."!
") end

					for k, v in pairs(val1[1]) do 
						if (k != "steamid" and string.sub(k, 1, 4) == 'slot') then --I think this is working. But v is not printing anything?							
							local tbl2 = {};
							if (v) then
								local tbl = glon.decode(v)
								tbl2 = tbl;

								if (tbl2 and tbl2.INV_SLOT) then
									self:ChatPrint("Slot "..tostring(tbl2.INV_SLOT).." loaded");
									self.LOOT_INVENTORY[tbl2.INV_SLOT] = tbl2;
									CheckMaxMods(tbl2, tbl2.QUALITY, tbl2.MODS);
								end
							end
						elseif (string.sub(k, 1, 5) == "equip") then
							local tbl = glon.decode(v);
							tbl2 = tbl;

							if (tbl2 and tbl2.EQ_SLOT) then
								self.LOOT_EQUIPED[tbl2.EQ_SLOT].ITEM = tbl2;					
								CheckMaxMods(tbl2, tbl2.QUALITY, tbl2.MODS);
							end
						end
					end

					print("Sending inventory.");
					self.LOADED_INV = true;
					timer.Simple(5, function()
						print("TImer send inv..");
						self:VerifyAndSendInv(true);
					end)
				else
					self:ChatPrint("Yo not loading right.");
					self:LoadInvDef();
				end
			end

			query1.onError = function(q, err)
				file.AppendLine("MYSQL_ERRORS.txt", "Loading Error for :" .. self:Nick() .. " -- 
"..err )
				self:ChatPrint("Loading from MYSQL failed, now loading from SQLLite, Report this, Load Error:" .. err);
				self:LoadInvDef();
			end

			query1:start();
		else
			return false;
		end
		return true;
	end

	function meta:SaveInventoryToMYSQL()
		if (!IsValid(self)) then return; end;

		if (!CONNECT) then
			self:ChatPrint("Not connected to MYSQL");
		end
		self:ChatPrint("Saving yo inv to the database homie")

		local name = self:SteamID();
		local str1 = '';
		local str2 ='';
		local str3 = '';
		local ii = ',';		

		for i = 1, table.Count(self.LOOT_EQUIPED) do
			str3 = str3 ..' equipslot'..tostring(i)..' = VALUES(equipslot'..tostring(i)..')'..ii;
			str1 = str1 .. ' equipslot'..tostring(i)..ii;
			local tb = {}
			local s = self.LOOT_EQUIPED*.ITEM;
			local tb = s;



			local iii = glon.encode(tb);
			str2 = str2 .." '".. iii.."'" .. ii;

		end

		for i = 1, self:GetNetworkedInt("MAX_INV_SLOTS") do
			if (i == 50) then ii = ''; end;
			str1 = str1 .. ' slot'..tostring(i)..ii;
			local tb = self.LOOT_INVENTORY*;

			local iii = glon.encode(tb);
			str2 = str2 .." '".. iii.."'" .. ii;
			str3 = str3..' slot'..tostring(i)..' = VALUES(slot'..tostring(i)..')'..ii;
		end


		file.Write("MYSQLLOG.txt", tostring("INSERT INTO playerinventories ( steamid," ..str1.. ") VALUES ( '"..name.."', "..str2.." ) ON DUPLICATE KEY UPDATE "..str3))
		local query1 = INVENTORY_MYSQL:query( "INSERT INTO playerinventories ( steamid," ..str1.. ") VALUES ( '"..name.."', "..str2.." ) ON DUPLICATE KEY UPDATE "..str3);
		query1.onError = function(Q,Err) 
			self:ChatPrint("Failed to save to MYSQL Please report this: " .. Err) 
			file.AppendLine("MYSQL_ERRORS.txt", "Save Error for :" .. self:Nick() .. " -- 
 "..err )
		end	

		query1.onSuccess = function(q) 
			if (q) then
				if (checkQuery2(q) == true) then
					if (IsValid(self)) then
					end
					myLog("Saved Inventory data for "..self:Nick().." to Mysql"); 
				else
					if (IsValid(self)) then
						//self:ChatPrint("Saved inventory data to MYSQL");
					end
				end
			end
		end
		query1:start()
	end

	function meta:SetPDataMYSQL( name, value )
		//print("TRYING TO QUERY");
		if (!IsValid(self)) then return; end;
		name = Format( "%s[%s]", self:UniqueID(), name )
		if (value == nil) then value = tostring(value) end; 
		local query1 = INVENTORY_MYSQL:query( "REPLACE INTO playerinventories ( steamid, value ) VALUES ( "..SQLStr(name)..", '"..value.."' )");
		query1.onError = function(Q,Err) self:print("Failed to save PData " .. Err) end
		query1.onSuccess = function(q) 
		
			if (q)
			then
				if (checkQuery2(q) == true)
				then
					print("Saved Inventory data to Mysql"); 
				end
			return; 
			end
		end
		query1:start()
		return;
	end

Okay. So it saves all the data to the MySQL database. That part works 100%. It’s just when loading the inventory from MySQL it won’t work. It gets all the slots and the steamID, but there is no value to them.

Add me on steam (Nazer VII) and I’ll probably be able to make your life alot easier.