Hey I made this for my 0.2 server as I didn't feel for updating to 0.3
However, the case was that I had made some scripts for my other server which is 0.3 and I didn't feel for remaking them to 0.2 sql functions~
Here I made this class so you can use 0.3 db crap in ur 0.2 serv
Make new file called db.lua in data folder. Then in global.lua write:
And in db.lua:
gz rep or ded
However, the case was that I had made some scripts for my other server which is 0.3 and I didn't feel for remaking them to 0.2 sql functions~
Here I made this class so you can use 0.3 db crap in ur 0.2 serv
Make new file called db.lua in data folder. Then in global.lua write:
Lua:
-- Colandus & grandmather sistemas
dofile('data/db.lua')
And in db.lua:
Lua:
--[[
CREDITS:
>> 80% COLANDUS
>> 20% GRANDMATHER, FIX MANY ISSUE!
]]--
db = {}
db.__index = db
function getConnection()
local env, con
if sqlType == "mysql" then
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
else -- sqlite
env = assert(luasql.sqlite3())
con = assert(env:connect(sqliteDatabase))
end
return env, con
end
function db.escapeString(str)
return "'" .. escapeString(str) .. "'"
end
function db.executeQuery(sql)
local env, con = getConnection()
cur = assert(con:execute(sql))
if(type(cur) ~= 'number') then
cur:close()
end
con:close()
env:close()
end
function db.getResult(sql)
local mt = {}
mt.env, mt.con = getConnection()
mt.cur = assert(mt.con:execute(sql))
if(mt.cur:numrows() > 0) then
mt.val = mt.cur:fetch({}, "a")
end
setmetatable(mt, db)
return mt
end
function db:getID()
return self.val and true or LUA_ERROR
end
function db:next()
self.val = self.cur:fetch(self.val, "a")
if self.val then
return true
end
end
function db:getDataInt(name)
if(self.val) then
return tonumber(self.val[name])
end
end
function db:getDataString(name)
if(self.val) then
return tostring(self.val[name])
end
end
function db:free()
self.cur:close()
self.con:close()
self.env:close()
end
gz rep or ded
Last edited: