Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::LUA

Quests::LUA Section regarding LUA scripts, help, questions, answers

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2019, 08:56 AM
phate8908
Fire Beetle
 
Join Date: Dec 2018
Posts: 12
Default 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
Reply With Quote
Reply

Tags
database, lua, mysql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 08:05 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3