daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Mar 14th, 2019 177 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DB = {}
  2. DB.User = "D3A4"
  3. DB.Pass = "theadminmodofd3"
  4. DB.DBase = "D3A"
  5.  
  6. function DB.Connect()
  7.     if (DB.CONNECTION) then return end
  8.    
  9.     DB.CONNECTION = mysqloo.connect("127.0.0.1", DB.User, DB.Pass, DB.DBase, 3306) 
  10.     DB.CONNECTION.onConnected = function()
  11.         D3A.Print("Database connection successful.")
  12.     end
  13.    
  14.     DB.CONNECTION.onConnectionFailed = function(s, e)
  15.         D3A.Error("Database connection failed: " .. e)
  16.     end
  17.    
  18.     DB.CONNECTION:connect()
  19. end
  20.  
  21. function DB.Escape(s)
  22.     return DB.CONNECTION:escape(s)
  23. end
  24.  
  25. function DB.EnsureConnection()
  26.     local status = DB.Connection:status()
  27.     while (status != 0) do
  28.         if (stat != 1) then
  29.             DB.Connection:connect()
  30.         end
  31.     end
  32. end
  33.  
  34. function DB.QueryWait(q)
  35.     q = q or function() end
  36.    
  37.     DB.EnsureConnection()
  38.    
  39.     local query = DB.Connection:query(q)
  40.     local retvar
  41.    
  42.     query.onSuccess = function(self)
  43.         retvar = self:getData()
  44.     end
  45.    
  46.     query.onError = function(self, e)
  47.         D3A.Error("MySQL error: " .. e .. "\nQuery given: " .. q)
  48.         retvar = {}
  49.     end
  50.    
  51.     query:start()
  52.     query:wait()
  53.    
  54.     return retvar
  55. end
  56.  
  57. function DB.Query(q, c)
  58.     DB.EnsureConnection()
  59.    
  60.     local query = DB.Connection:query(q)
  61.    
  62.     query.onSuccess = function(self)
  63.         c(self:getData())
  64.     end
  65.    
  66.     query.onError = function(self, e)
  67.         D3A.Error("MySQL error: " .. e .. "\nQuery given: " .. q)
  68.     end
  69.    
  70.     query:start()
  71. end
  72.  
  73. DB.Connect()
  74.  
  75. timer.Create("DB.Keepalive", 30, 0, function()
  76.     if (DB) then
  77.         DB.Query("SHOW VARIABLES LIKE 'keepalive'")
  78.     end
  79. 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