Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. local connectedDatabeses = {}
  2. local stats = {}
  3.  
  4. local databases = {"dayz"}
  5.  
  6. function connectNewDatabase(data)
  7. local connection = dbConnect("mysql","dbname="..data..";host="..get("mysql_host")..";port="..3306, get("mysql_username"), get("mysql_password"), "autoreconnect=1")
  8. if connection then
  9. connectedDatabeses[data] = connection
  10. if not stats[data] then
  11. stats[data] = {}
  12. stats[data]["success"] = 1
  13. else
  14. stats[data]["success"] = stats[data]["success"] + 1
  15. end
  16. outputDebugString("MYSQL is connected to: "..data.."; Tried: "..(stats[data]["success"] or 0).." time(s)")
  17. setTimer(function() connectNewDatabase(data) end, 60000*15, 1)
  18. else
  19. connectedDatabeses[data] = false
  20. if not stats[data] then
  21. stats[data] = {}
  22. stats[data]["failed"] = 1
  23. else
  24. stats[data]["failed"] = stats[data]["failed"] + 1
  25. end
  26. outputDebugString("MYSQL Connection failed: "..data.."; Tried: "..(stats[data]["failed"] or 0).." time(s)")
  27. setTimer(function() connectNewDatabase(data) end, 60000, 1)
  28. end
  29. end
  30.  
  31. addEventHandler("onResourceStart", resourceRoot, function()
  32. for i, k in pairs(databases) do
  33. connectNewDatabase(k)
  34. end
  35. end)
  36.  
  37. function getConnection(data)
  38. if not data then data = databases[1] end
  39. if connectedDatabeses[data] then
  40. return connectedDatabeses[data]
  41. else
  42. return false
  43. end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement