Advertisement
Guest User

query

a guest
Jun 21st, 2016
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. if(not fs.exists("json")) then
  2.   print("Whoah there! This utility will not work correctly without the json decoding API by ElvishJerricco!")
  3.   return
  4. end
  5.  
  6. os.loadAPI("json")
  7.  
  8. function queryServer(host,username,password,query)
  9.   ping = http.post(
  10.     "http://budgieblue.net23.net/queryServer.php",
  11.     "host="..host.."&username="..username.."&password="..password.."&query="..query
  12.   )
  13.   response = ping.readAll()
  14.   ping.close()
  15.   return json.decode( response )
  16. end
  17.  
  18. function queryDatabase(host,username,password,dbname,query)
  19.   ping = http.post(
  20.     "http://budgieblue.net23.net/queryDatabase.php",
  21.     "host="..host.."&username="..username.."&password="..password.."&dbname="..dbname.."&query="..query
  22.   )
  23.   response = ping.readAll()
  24.   ping.close()
  25.   return json.decode( response )
  26. end --Returns the rows of your query
  27. --EXAMPLE:
  28. --[[
  29. SELECT * FROM users WHERE username="user"
  30.  
  31. If you have a database setup like that,
  32. it would return all the rows in the entry
  33. that has a matching username, as variables.
  34. Basically if a password was in a column named
  35. password,it would return
  36. {password="whatever it was"}.
  37. So you can access it by [query].password.
  38.  
  39. Overcomplicated (in my opinion) ;P
  40. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement