PDA

View Full Version : MySQL connect


phate8908
01-02-2019, 08:56 AM
Enjoy!

Files needed:
mysql.lua (https://raw.githubusercontent.com/luapower/luapower-all/master/mysql.lua)
mysql_h.lua (https://raw.githubusercontent.com/luapower/luapower-all/master/mysql_h.lua)
JSON.lua (https://raw.githubusercontent.com/jiyinyiyong/json-lua/master/JSON.lua)

MySQLi.lua

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(po rt))
end
return MySQLi

append to general_ext.lua

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