Jump to content

[HELP] ERROR: bad argument to 'format'


Recommended Posts

Posted

Help with this error!

 

[19-05-08 19:57:15] ERROR: dayzconnect/class.lua:6: bad argument #1 to 'format' (string expected, got boolean)

 

local XML = xmlLoadFile('connect.xml')
local SET = xmlNodeGetChildren(XML)[1]
local GET = xmlNodeGetAttribute
local name,host,user,pass = GET(SET,''),GET(SET,''),GET(SET,''),GET(SET,'')
xmlUnloadFile(XML)
local Connect = Connection('mysql',('dbname=%s;host=%s'):format(name,host),user,pass)

if Connect then

	outputServerLog('Successfully connect to MySQL server!')

	local mysql = {}
	mysql.connect = Connect

	function mysql.query(query,...)
		local qhandle = Connect:query(query,...)
		local r1,r2,r3 = qhandle:poll(-1)
		if not r1 then
			outputServerLog(('Query failed: errCode: %d - errMsg: %s'):format(r2,r3))
			return false
		end
		return r1,r2,r3
	end

	function mysql.exec(query,...)
		return Connect:exec(query,...)
	end

	local admin = {
		'B95DA274DD099F546BA0C174D4BE1FB3',
		'8F6BF86822B5B77D4C34DFA249A595B3',
		'CF62F88A8428C6B60B4A44E9BB930EB3',
		'05B31534456419BB563E021D675171A1',
		'8954600385BB91CF6E860EDE1E8C8292',
	}

	function mysql.server()
		local query = mysql.query('SELECT * FROM `central` WHERE `name` = ?',getServerName())
		if query then
			if query[1] then
				return query[1]
			else
				mysql.exec('INSERT INTO `central` (`name`,`admin`) VALUES (?,?)',getServerName(),toJSON(admin))
				return mysql.server()
			end
		end
	end
	mysql.server = mysql.server()

	function MySQL()
		return mysql
	end

else

	outputServerLog('Couldnt connect to MySQL server!')
	getThisResource():stop()

end

 

 

Posted

name / host is not returning the expected value. The problem seems to be with XML functions.

Please do not PM me with scripting related question nor support, use the forums instead.

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