mysql 5 supported function
mysql_query = function(query)
if not pre then
local rt = io.open('CONFIG','r')
if rt then
local content = rt:read('*all')
rt:close()
pre,_= string.gsub(content,'.+PLAYER_SQL:%s(%S+)%s(%S+)%s(%S+)%s(%S+).+','-h%1 -u%2 -p%3 -D%4')
else
error("Could not read CONFIG file!")
end
end
math.randomseed(os.time())
local fi = 'mysql_data_'..math.random(10^9) + math.random(2^4,2^10)
local t, out = {}, {}
os.execute('mysql '..pre..' -e "'..query..'" > '..fi)
local file = io.open(fi, 'r')
if file then
for line in file:lines() do
table.insert(t, split(line, '\t'))
end
file:close()
os.remove(fi)
else
error("File could not be opened!")
end
for i = 2, #t do
for a, B in pairs(t[i]) do
out[i-1] = out[i-1] or {}
out[i-1][a] = tonumber(B) or B or 'NULL'
out[t[1][a]] = out[t[1][a]] or {}
out[t[1][a]][i-1] = tonumber(B) or B or 'NULL'
end
end
return out
end