Advertisement
Guest User

Untitled

a guest
Aug 13th, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. -- Called when the server initializes.
  2. function GM:Initialize()
  3. ErrorNoHalt"----------------------\n"
  4. ErrorNoHalt(os.date().." - Server starting up\n")
  5. ErrorNoHalt"----------------------\n"
  6. local host = self.Config["MySQL Host"]
  7. local username = self.Config["MySQL Username"]
  8. local password = self.Config["MySQL Password"]
  9. local database = self.Config["MySQL Database"]
  10.  
  11. -- Initialize a connection to the MySQL database.
  12. self.DB, err = mysqloo.connect(self.Config["MySQL Host"], self.Config["MySQL Username"], self.Config["MySQL Password"], self.Config["MySQL Database"], 3306)
  13. if (!self.DB) then
  14. error("You didn't setup the SQL correctly!")
  15. end
  16.  
  17. self.DB.OnError = function(self, err)
  18. print("DB Connection error: "..err)
  19. end
  20.  
  21. self.DB.OnConnectionFailed = function(self, err)
  22. error("You didn't setup the SQL Correctly!\n Here's what I got: \n "..err)
  23. end
  24.  
  25. self.DB.OnConnected = function()
  26.  
  27.  
  28. print("Successfully connected to database!")
  29. timer.Create("mysqloo.checkConnection", 30, 0, function()
  30. local q = self.DB:query("SELECT 1+1")
  31. q:start();
  32. local status = self.DB:status()
  33. if (status == mysqloo.DATABASE_NOT_CONNECTED) then
  34. self.DB:connect()
  35. timer.Destroy("mysqloo.checkConnection")
  36. end
  37. end)
  38. end
  39.  
  40. self.DB:connect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement