function getOrganizationID(plr)
local result = exports["ogrpg-db"]:dbGet("SELECT * FROM ogrpg_user WHERE uid=?", getElementData(plr, "player:uid"))
if #result > 0 then
return result[1].id
else
return false
end
end
function getOrganizationName(plr,id)
local result = exports["ogrpg-db"]:getRekord("SELECT * FROM og_organizations WHERE id=?", id)
if #result > 0 then
return result[1].name
else
return false
end
end
function isLider(plr)
local result = exports["ogrpg-db"]:getRekord("SELECT * FROM ogrpg_user WHERE uid=? AND rank=? AND id=?", getElementData(plr, "player:uid"), "Lider", getOrganizationID(plr))
if #result > 0 then
return true
else
return false
end
end
function updateMembersList(plr)
local result = exports["ogrpg-db"]:getRekord("SELECT * FROM `og_orgplayers` x, `og_users` u WHERE x.`id`=? AND u.`id`=x.`uid`", getOrganizationID(plr))
if #result > 0 then
for i,v in ipairs(result) do
triggerClientEvent("onClientShowPlayersOrganization", plr, v.id, v.login, v.rank)
end
end
end
function getOrganizationID(plr)
local result = exports["ogrpg-db"]:dbGet("SELECT * FROM ogrpg_user WHERE uid=?", getElementData(plr, "player:uid"))
if result and #result > 0 then
return result[1].id
else
return false
end
end
function getOrganizationName(plr,id)
local result = exports["ogrpg-db"]:dbGet("SELECT * FROM og_organizations WHERE id=?", id)
if result and #result > 0 then
return result[1].name
else
return false
end
end
function isLider(plr)
local result = exports["ogrpg-db"]:dbGet("SELECT * FROM ogrpg_user WHERE uid=? AND rank=? AND id=?", getElementData(plr, "player:uid"), "Lider", getOrganizationID(plr))
if result and #result > 0 then
return true
else
return false
end
end
function updateMembersList(plr)
local result = exports["ogrpg-db"]:dbGet("SELECT * FROM `og_orgplayers` x, `og_users` u WHERE x.`id`=? AND u.`id`=x.`uid`", getOrganizationID(plr))
if result and #result > 0 then
for i,v in ipairs(result) do
triggerClientEvent("onClientShowPlayersOrganization", plr, v.id, v.login, v.rank)
end
end
end
-- Settings
DBHandler=nil
DBName="db_xxx"
DBUser="db_xxx"
DBPass="xxx"
DBHost="sqlxxx"
-- Functions
function dbSet(...)
if not {...} then return end
local stringe=dbPrepareString(DBHandler,...)
local query=dbExec(DBHandler, stringe)
return query
end
function dbGet(...)
if not {...} then return end
local stringe=dbPrepareString(DBHandler,...)
local query=dbQuery(DBHandler, stringe)
local result=dbPoll(query, -1)
return result
end
addEventHandler("onResourceStart", resourceRoot, function()
DBHandler=dbConnect("mysql", "dbname="..DBName..";host="..DBHost.."", DBUser, DBPass, "share=1;autoreconnect=1")
if DBHandler then
outputDebugString("* Connect to server MYSQL...")
dbSet("SET NAMES utf8")
else
outputDebugString("* No Connecting to server MYSQL..")
end
end)
local SQL_LOGIN="db_xxx"
local SQL_PASSWD="xxx"
local SQL_DB="db_xxx"
local SQL_HOST="sql-xxx"
local SQL_PORT=3306
local root = getRootElement()
local SQL
local function connect()
SQL = mysql_connect(SQL_HOST, SQL_LOGIN, SQL_PASSWD, SQL_DB, SQL_PORT)
if (not SQL) then
outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
else
--mysql_query(SQL,"SET NAMES utf8")
--outputServerLog("Modul mysql polaczony!")
end
end
local function keepAlive()
if (not mysql_ping(SQL)) then
outputServerLog("Zerwane polaczenie z baza danych, nawiazywanie...")
connect()
end
end
addEventHandler("onResourceStart",getResourceRootElement(),function()
connect()
setTimer(keepAlive, 30000, 0)
end)
function esc(value)
return mysql_escape_string(SQL,value)
end
function pobierzTabeleWynikow(query)
local result=mysql_query(SQL,query)
if (not result) then
outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
outputServerLog("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
return nil
end
local tabela={}
for result,row in mysql_rows_assoc(result) do
table.insert(tabela,row)
end
mysql_free_result(result)
return tabela
end
function pobierzWyniki(query)
local result=mysql_query(SQL,query)
if (not result) then return nil end
row = mysql_fetch_assoc(result)
mysql_free_result(result)
return row
end
function zapytanie(query)
local result=mysql_query(SQL,query)
if (result) then mysql_free_result(result) return true end
return
end
function insertID()
return mysql_insert_id(SQL)
end
function affectedRows()
return mysql_affected_rows(SQL)
end
function fetchRows(query)
local result=mysql_query(SQL,query)
if (not result) then return nil end
local tabela={}
while true do
local row = mysql_fetch_row(result)
if (not row) then break end
table.insert(tabela,row)
end
mysql_free_result(result)
return tabela
end
function getSQLLink()
return SQL
end
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach