summaryrefslogtreecommitdiff
path: root/gamemode/sv_various/mysql.lua
diff options
context:
space:
mode:
authorApickx <Apickx@cogarr.org>2015-12-28 19:18:30 -0500
committerApickx <Apickx@cogarr.org>2015-12-28 19:18:30 -0500
commit868e729d68b5913716bfe5ddb512f4099851e9a2 (patch)
tree6441108754145dfd68a6e23bea382b5cb1ab63d5 /gamemode/sv_various/mysql.lua
downloadgearfox-868e729d68b5913716bfe5ddb512f4099851e9a2.tar.gz
gearfox-868e729d68b5913716bfe5ddb512f4099851e9a2.tar.bz2
gearfox-868e729d68b5913716bfe5ddb512f4099851e9a2.zip
Initial commitHEADmaster
Diffstat (limited to 'gamemode/sv_various/mysql.lua')
-rw-r--r--gamemode/sv_various/mysql.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/gamemode/sv_various/mysql.lua b/gamemode/sv_various/mysql.lua
new file mode 100644
index 0000000..4e51e6c
--- /dev/null
+++ b/gamemode/sv_various/mysql.lua
@@ -0,0 +1,38 @@
+pcall(require,"mysqloo")
+
+if (!mysqloo) then Msg("--- MySQL functions disabled. MySQLoo Module not found! ---\n") return end
+
+mysql = {}
+
+local Retries = 0
+
+function mysql:Start(Host,User,Pass,Database)
+ local db = mysqloo.connect(Host,User,Pass,Database)
+ function db.onConnectionFailed(self,er) Msg( "Connection failed: "..er.."\n" ) end
+ function db.onConnected(self) Msg( "Connection has been established.\n" ) end
+ db:connect()
+ return db
+end
+
+function mysql:Query(DAT,DB)
+ local db = DB or nil
+ if (!db) then Msg( "Database does not exist. Call mysql:Start()\n" ) return end
+ if (db:status() == mysqloo.DATABASE_NOT_CONNECTED) then
+ if (Retries < 4) then
+ Msg( "Reconnecting...\n" )
+ db:connect()
+ timer.Simple(5,function() self:Query(DAT,DB) end)
+
+ Retries = Retries+1
+ else Retries = 0 end
+ return
+ end
+
+ local DATABASE = db:query(DAT)
+ if (DATABASE) then
+ DATABASE:start()
+ function DATABASE.onError(s,er) Msg( er.."\n" ) end
+ function DATABASE.onFailure(s,er) Msg( er.."\n" ) end
+ end
+ return DATABASE
+end