EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::LUA (https://www.eqemulator.org/forums/forumdisplay.php?f=680)
-   -   MySQL connect (https://www.eqemulator.org/forums/showthread.php?t=42243)

phate8908 01-02-2019 08:56 AM

MySQL connect
 
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



All times are GMT -4. The time now is 07:50 AM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.