Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local connectedDatabeses = {}
- local stats = {}
- local databases = {"dayz"}
- function connectNewDatabase(data)
- local connection = dbConnect("mysql","dbname="..data..";host="..get("mysql_host")..";port="..3306, get("mysql_username"), get("mysql_password"), "autoreconnect=1")
- if connection then
- connectedDatabeses[data] = connection
- if not stats[data] then
- stats[data] = {}
- stats[data]["success"] = 1
- else
- stats[data]["success"] = stats[data]["success"] + 1
- end
- outputDebugString("MYSQL is connected to: "..data.."; Tried: "..(stats[data]["success"] or 0).." time(s)")
- setTimer(function() connectNewDatabase(data) end, 60000*15, 1)
- else
- connectedDatabeses[data] = false
- if not stats[data] then
- stats[data] = {}
- stats[data]["failed"] = 1
- else
- stats[data]["failed"] = stats[data]["failed"] + 1
- end
- outputDebugString("MYSQL Connection failed: "..data.."; Tried: "..(stats[data]["failed"] or 0).." time(s)")
- setTimer(function() connectNewDatabase(data) end, 60000, 1)
- end
- end
- addEventHandler("onResourceStart", resourceRoot, function()
- for i, k in pairs(databases) do
- connectNewDatabase(k)
- end
- end)
- function getConnection(data)
- if not data then data = databases[1] end
- if connectedDatabeses[data] then
- return connectedDatabeses[data]
- else
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement