Advertisement
LukaSJ0

Example Script

Apr 27th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.85 KB | None | 0 0
  1. # simplified handler for database access
  2. module Database
  3.     # url the post is being made to
  4.     @@url = "your web url that hosts the PHP script"
  5.     # simple function to group posting to the actual URL
  6.     def self.makeRequest(type, data = {})
  7.         data["type"] = type
  8.         return pbPostData(@@url,data)
  9.     end
  10.     # function used to add row to specific table
  11.     def self.addTestSubject(name, surname, age)
  12.         data = {
  13.             "name" => name,
  14.             "surname" => surname,
  15.             "age" => age
  16.         }
  17.         self.makeRequest("addTestSubject",data)
  18.     end
  19. end
  20.  
  21. # this writes data to table
  22. Database.addTestSubject("Tim","Timmons",20)
  23.  
  24. # this reads the data from the table
  25. req = Database.makeRequest("getTestSubjects").split("\r\n")
  26. lines = []
  27. # this splits the data up into an array to make it more usable
  28. for r in req
  29.     lines.push(r.split("</s>"))
  30. end
  31. # this prints out the result
  32. p lines
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement