projecteq-projecteqquests/global/lib/lua/5.1/luasql_ext.lua
Trust b830fea185 [Feature] LUA SQL Support (Linux)
Copy the luasql_ext.lua from global/lib/lua/5.1/ and place that in the root game folder with your eqemu_config.json and edit the database information to mirror your connection requirements.

Example lua use:

```lua
local mysql = require("luasql_ext");

for id, level, locked_out in mysql.rows(con,string.format("SELECT DISTINCT c.`id`, c.`level` FROM group_id g INNER JOIN character_data c ON c.id = g.character_id WHERE g.group_id = %s", group:GetID())) do
			if tonumber(level) <= dia_min_level then dia_min_level = tonumber(level) end
			if tonumber(level) >= dia_max_level then dia_max_level = tonumber(level) end
			dia_total_level = dia_total_level + tonumber(level);
			dia_member_count = dia_member_count + 1;
		end

```

```lua
local mysql = require("luasql_ext");

		for id,name in mysql.rows(con,"SELECT id from npc_types WHERE id >= 211000 and id < 212000 and disable_instance = 1") do
			disable_instance[id] = tonumber(id);
		end
```
2024-11-04 21:06:51 -05:00

41 lines
1 KiB
Lua

--MySQL connection information to use in conjunction with luamysql
--This can be dropped in the eqemu server root directory and will be automatically referenced
--this information can be pulled from the eqemu_config.xml file in the eqemu server root
-- load driver
local driver = require("luasql_mysql");
--declare table
local luasql_ext = {};
--set database information
local database_name = "local_dev";
local user = "root";
local password = "eqemu";
local ip_addr = "localhost";
local port = "3306";
function luasql_ext.env(e)
-- create environment object
env = assert (driver.mysql());
return env;
end
function luasql_ext.con(e)
-- connect to data source
con = assert (env:connect(database_name,user,password,ip_addr,port));
return con;
end
function luasql_ext.rows(connection,statement)
env = assert (driver.mysql());
local con = connection or assert (env:connect(database_name,user,password,ip_addr,port));
local cur = assert (con:execute(statement));
con:close();
env:close();
return function()
return cur:fetch()
end
end
return luasql_ext;