Guest User

Untitled

a guest
Mar 20th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. -- Settings
  2. DBHandler=nil
  3. DBName="db_41935"
  4. DBUser="db_41935"
  5. DBPass="*************"
  6. DBHost="87.98.236.134"
  7.  
  8. -- Functions
  9. function dbSet(...)
  10.     if not {...} then return end
  11.     local query=dbExec(DBHandler, ...)
  12.     return query
  13. end
  14.  
  15. function dbGet(...)
  16.     if not {...} then return end
  17.     local query=dbQuery(DBHandler, ...)
  18.     local result=dbPoll(query, -1)
  19.     return result
  20. end
  21.  
  22.  
  23. addEventHandler("onResourceStart", resourceRoot, function()
  24.     DBHandler=dbConnect("mysql", "dbname="..DBName..";host="..DBHost.."", DBUser, DBPass, "share=1")
  25.     if DBHandler then
  26.         outputDebugString("* Connect to server MYSQL...")
  27.     else
  28.         outputDebugString("* No Connecting to server MYSQL..")
  29.     end
  30. end)
  31.  
  32.  
  33. local SQL_LOGIN="db_41935"
  34. local SQL_PASSWD="*********"
  35. local SQL_DB="db_41935"
  36. local SQL_HOST="87.98.236.134"
  37. local SQL_PORT=3306
  38.  
  39. local root = getRootElement()
  40.  
  41. local SQL
  42.  
  43. local function connect()
  44.     SQL = mysql_connect(SQL_HOST, SQL_LOGIN, SQL_PASSWD, SQL_DB, SQL_PORT)
  45.     if (not SQL) then
  46.         outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
  47.     else
  48.     end
  49.  
  50. end
  51.  
  52.  
  53. local function keepAlive()
  54.     if (not mysql_ping(SQL)) then
  55.         outputServerLog("Zerwane polaczenie z baza danych, nawiazywanie...")
  56.         connect()
  57.     end
  58. end
  59. addEventHandler("onResourceStart",getResourceRootElement(),function()
  60.     connect()
  61.     setTimer(keepAlive, 30000, 0)
  62. end)
  63.  
  64. function esc(value)
  65.     return mysql_escape_string(SQL,value)
  66. end
  67.  
  68. function pobierzTabeleWynikow(query)
  69.     local result=mysql_query(SQL,query)
  70.     if (not result) then
  71.         outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
  72.         outputServerLog("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
  73.         return nil
  74.     end
  75.     local tabela={}
  76.     for result,row in mysql_rows_assoc(result) do
  77.         table.insert(tabela,row)
  78.     end
  79.     mysql_free_result(result)
  80.     return tabela
  81. end
  82.  
  83. function pobierzWyniki(query)
  84.     local result=mysql_query(SQL,query)
  85.     if (not result) then return nil end
  86.     row = mysql_fetch_assoc(result)
  87.     mysql_free_result(result)
  88.     return row
  89. end
  90.  
  91.  
  92. function zapytanie(query)
  93.     local result=mysql_query(SQL,query)
  94.     if (result) then mysql_free_result(result) return true end
  95.     return
  96. end
  97.  
  98. function insertID()
  99.     return mysql_insert_id(SQL)
  100. end
  101.  
  102. function affectedRows()
  103.     return mysql_affected_rows(SQL)
  104. end
  105.  
  106.  
  107. function fetchRows(query)
  108.     local result=mysql_query(SQL,query)
  109.     if (not result) then return nil end
  110.     local tabela={}
  111.  
  112.     while true do
  113.         local row = mysql_fetch_row(result)
  114.         if (not row) then break end
  115.         table.insert(tabela,row)
  116.     end
  117.     mysql_free_result(result)
  118.     return tabela
  119. end
  120.  
  121.  
  122. function getSQLLink()
  123.     return SQL
  124. end
Advertisement
Add Comment
Please, Sign In to add comment