Ceziy

DBApi.lua

Nov 27th, 2023 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. --Get client's info from DB
  2. function getDB(card_num) do
  3.     n = 0
  4.     file = io.open("client_base.txt")
  5.     for line in file:lines() do
  6.         arr = {}
  7.         temp = {}
  8.         temp = string.gmatch(line, "[^ ]+")
  9.         c = 0
  10.         arr = {num = "", name = "", bal = 0.0, pass = "", index = 0}
  11.         for i in temp do
  12.             if c == 0 then arr.num=i
  13.             elseif c == 1 then arr.name=i
  14.             elseif c == 2 then arr.bal=i
  15.             elseif c == 3 then arr.pass=i
  16.             end
  17.             c = c + 1
  18.         end
  19.         if tostring(arr.num) == tostring(card_num) then
  20.             io.close(file)
  21.             arr.index = n
  22.             return arr
  23.         end
  24.         n = n + 1
  25.     end
  26. end
  27. end
  28.  
  29. --Edit file's line
  30.  
  31. function editLine(path, num, ncont)
  32.     local file = io.open(path, 'r')
  33.     local fileContent = {}
  34.     for line in file:lines() do
  35.         table.insert (fileContent, line)
  36.     end
  37.     io.close(file)
  38.  
  39.     fileContent[tonumber(num) + 1] = tostring(ncont)
  40.  
  41.     file = io.open(path, 'w')
  42.     for index, value in ipairs(fileContent) do
  43.         --print(value)
  44.         file:write(value .. '\n')
  45.     end
  46.     io.close(file)
  47. end
Add Comment
Please, Sign In to add comment