Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. --[[
  2. Resource: OURGame v2
  3. Developers: Split <split.programista@gmail.com>
  4. You have no right to use this code without my permission.
  5. (c) 2015 <split.programista@gmail.com>. All rights reserved.
  6. ]]
  7.  
  8. -- Settings
  9. DBHandler=nil
  10. DBName="I DB"
  11. DBUser="TUTAJ DB"
  12. DBPass="TUTAJ PASSWORD"
  13. DBHost="TUTAJ MAM HOST"
  14.  
  15. -- Functions
  16. function dbSet(...)
  17. if not {...} then return end
  18. local stringe=dbPrepareString(DBHandler,...)
  19. local query=dbExec(DBHandler, stringe)
  20. return query
  21. end
  22.  
  23. function dbGet(...)
  24. if not {...} then return end
  25. local stringe=dbPrepareString(DBHandler,...)
  26. local query=dbQuery(DBHandler, stringe)
  27. local result=dbPoll(query, -1)
  28. return result
  29. end
  30.  
  31.  
  32. addEventHandler("onResourceStart", resourceRoot, function()
  33. DBHandler=dbConnect("mysql", "dbname="TU MAM DB";host="HOST MAM"", DB, PASS, "share=1;autoreconnect=1")
  34. if DBHandler then
  35. outputDebugString("* Connect to server MYSQL...")
  36. dbSet("SET NAMES utf8")
  37. else
  38. outputDebugString("* No Connecting to server MYSQL..")
  39. end
  40. end)
  41.  
  42.  
  43. local SQL_LOGIN="TU MAM NAME"
  44. local SQL_PASSWD="TU MAM HASLO"
  45. local SQL_DB="TUTAJ MAM DB"
  46. local SQL_HOST="TUTAJ MAM HOST"
  47. local SQL_PORT=3306
  48.  
  49. local root = getRootElement()
  50.  
  51. local SQL
  52.  
  53. local function connect()
  54. SQL = mysql_connect(SQL_HOST, SQL_LOGIN, SQL_PASSWD, SQL_DB, SQL_PORT)
  55. if (not SQL) then
  56. outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
  57. else
  58. --mysql_query(SQL,"SET NAMES utf8")
  59. --outputServerLog("Modul mysql polaczony!")
  60. end
  61.  
  62. end
  63.  
  64.  
  65. local function keepAlive()
  66. if (not mysql_ping(SQL)) then
  67. outputServerLog("Zerwane polaczenie z baza danych, nawiazywanie...")
  68. connect()
  69. end
  70. end
  71. addEventHandler("onResourceStart",getResourceRootElement(),function()
  72. connect()
  73. setTimer(keepAlive, 30000, 0)
  74. end)
  75.  
  76. function esc(value)
  77. return mysql_escape_string(SQL,value)
  78. end
  79.  
  80. function pobierzTabeleWynikow(query)
  81. local result=mysql_query(SQL,query)
  82. if (not result) then
  83. outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
  84. outputServerLog("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
  85. return nil
  86. end
  87. local tabela={}
  88. for result,row in mysql_rows_assoc(result) do
  89. table.insert(tabela,row)
  90. end
  91. mysql_free_result(result)
  92. return tabela
  93. end
  94.  
  95. function pobierzWyniki(query)
  96. local result=mysql_query(SQL,query)
  97. if (not result) then return nil end
  98. row = mysql_fetch_assoc(result)
  99. mysql_free_result(result)
  100. return row
  101. end
  102.  
  103.  
  104. function zapytanie(query)
  105. local result=mysql_query(SQL,query)
  106. if (result) then mysql_free_result(result) return true end
  107. return
  108. end
  109.  
  110. function insertID()
  111. return mysql_insert_id(SQL)
  112. end
  113.  
  114. function affectedRows()
  115. return mysql_affected_rows(SQL)
  116. end
  117.  
  118.  
  119. function fetchRows(query)
  120. local result=mysql_query(SQL,query)
  121. if (not result) then return nil end
  122. local tabela={}
  123.  
  124. while true do
  125. local row = mysql_fetch_row(result)
  126. if (not row) then break end
  127. table.insert(tabela,row)
  128. end
  129. mysql_free_result(result)
  130. return tabela
  131. end
  132.  
  133.  
  134. function getSQLLink()
  135. return SQL
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement