Enjoy!
Files needed:
mysql.lua
mysql_h.lua
JSON.lua
MySQLi.lua
Code:
local mysql = require('mysql')
local MySQLi = {}
function MySQLi:Connect()
local Settings = eq.GetSettings()
local db = Settings["server"]["database"]["db"]
local host = Settings["server"]["database"]["host"]
local user = Settings["server"]["database"]["username"]
local pass = Settings["server"]["database"]["password"]
local port = Settings["server"]["database"]["port"]
return mysql.connect(host,user,pass,db,'utf8',tonumber(port))
end
return MySQLi
append to general_ext.lua
Code:
function eq.ReadFile(file)
local f = io.open(file, "rb")
if f then f:close() end
lines = {}
if f ~= nil then
for line in io.lines(file) do
lines[#lines + 1] = line
end
end
return lines
end
function eq.GetSettings()
local json = require "JSON"
local Message = eq.ReadFile("eqemu_config.json")
local configFile = ""
for k,v in pairs(Message) do
configFile = configFile .. v
end
return json:decode(configFile)
end