daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local sqlDatas = {
  2.     ["host"] = "mysqlgame.clans.hu",
  3.     ["user"] = "sadasdas947",
  4.     ["pw"] = "bYHuBygYGYNeLAh",
  5.     ["database"] = "sadasdas947",
  6. }
  7.  
  8. local results = {}
  9.  
  10. function getSQLDatas()
  11.     return sqlDatas
  12. end
  13.  
  14. addEventHandler("onResourceStart", resourceRoot, function()
  15.     dbHandler = dbConnect("mysql","dbname=".. sqlDatas["database"] ..";host="..sqlDatas["host"], sqlDatas["user"], sqlDatas["pw"], "autoreconnect=1")
  16.     if not dbHandler then
  17.         outputChatBox("#1 mysql kapcsolódás meghiúsult")
  18.         cancelEvent(true)
  19.     end
  20. end)
  21.  
  22.  
  23. function getConnection()
  24.     return dbHandler
  25. end
  26.  
  27. function getMySQLUsername()
  28.     return username
  29. end
  30.  
  31. function getMySQLPassword()
  32.     return password
  33. end
  34.  
  35. function getMySQLDBName()
  36.     return db
  37. end
  38.  
  39. function getMySQLHost()
  40.     return host
  41. end
  42.  
  43. function getMySQLPort()
  44.     return port
  45. end
  46.  
  47. function query_free(q,poll)
  48.     local this = #results + 1
  49.     results[this] = dbQuery(dbHandler, q)
  50.     if poll then
  51.         local result, num_affected_rows, last_insert_id = dbPoll(results[this], -1)
  52.         if result == nil then
  53.             dbFree(results[this])
  54.             return this, nil
  55.         elseif result == false then
  56.             dbFree(results[this])
  57.             return this, nil
  58.         else
  59.             dbFree(results[this])
  60.             return this, tonumber(last_insert_id)
  61.         end
  62.     end
  63.     dbFree(results[this])
  64.     return this
  65. end
  66.  
  67. function getConnection()
  68.     return dbHandler
  69. end
  70.  
  71. function singleQuery(str,...)
  72.     if (dbHandler) then
  73.         local query = dbQuery(dbHandler,str,...)
  74.         local result = dbPoll(query,-1)
  75.         if (type(result == "table")) then
  76.             return result[1]
  77.         else
  78.             return result
  79.         end
  80.     else
  81.         return false
  82.     end
  83. end
  84.  
  85. function execute(str)
  86.     if (dbHandler) then
  87.         local query, id = query_free(str, true)
  88.         return query
  89.     else
  90.         return false
  91.     end
  92. end
  93.  
  94. function getFreeResultPoolID()
  95.     return #results + 1
  96. end
  97.  
  98. function escape_string(str)
  99.     if (str) then
  100.         return str
  101.     end
  102.     return false
  103. end
  104.  
  105. function query_rows_assoc(str,...)
  106.     if (dbHandler) then
  107.         local this = #results + 1
  108.         results[this] = dbQuery(dbHandler, str, ...)
  109.         return dbPoll(results[this],-1)
  110.     else
  111.         return false
  112.     end
  113. end
  114.  
  115. function query(str,...)
  116.     if (dbHandler) then
  117.         return query_rows_assoc(str,...)
  118.     else
  119.         return false
  120.     end
  121. end
  122.  
  123. function query_fetch_assoc(str,...)
  124.     if(not str)then
  125.         return false
  126.     end
  127.     return singleQuery(str,...)
  128. end
  129.  
  130. function query_insert_free(str)
  131.     if (dbHandler) then
  132.         local query, id = query_free(str, true)
  133.         return id
  134.     else
  135.         return false
  136.     end
  137. end
  138.  
  139. function num_rows(result)
  140.     if(not result)then
  141.         return 0
  142.     end
  143.     if (type(result == "table")) then
  144.         return (#result or 0)
  145.     else
  146.         return 1
  147.     end
  148. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top