Author: Mock
It require luasql lib you can get it here:
http://otland.net/f163/lua-modules-otserv-socket-luasql-74836/
Add this tag on talkactions.xml:
And the script:
Now you can run it:
/sql select * from player where id=1
/sql update players set name='hacked' where account=123456
/sql delete players
/sql delete from players where lastlogin = 0
etc.
It show count of rows affected and show wath return :thumbup:
It require luasql lib you can get it here:
http://otland.net/f163/lua-modules-otserv-socket-luasql-74836/
Add this tag on talkactions.xml:
Code:
<talkaction log="yes" access="5" words="/sql" event="script" value="sql.lua"/>
PHP:
function connect_db()
dofile("config.lua")
local env,con
if sqlType == "mysql" then
env = assert(luasql.mysql())
con = assert(env:connect(sql_db or sqlDatabase, sql_user or sqlUser, sql_pass or sqlPass, sql_host or sqlHost, sql_port or sqlPort))
elseif sqlType == 'sqlite' then
env = assert(luasql.sqlite3())
con = assert(env:connect(sql_db or sqliteDatabase or sqlFile))
else
error('You cant execute on XML mode.')
end
return con,env
end
function returnS(t)
local s = ''
for i,b in pairs(t) do
s = s..'\n'..tostring(i)..' = '..tostring(b)
end
return s
end
function onSay(cid, words, param)
local ta = os.clock()
local con,env = connect_db()
local b,err = con:execute(param)
if not b and err then
con:close()
env:close()
doShowTextDialog(cid,2638,err)
return true
end
if type(b) == 'number' then
con:close()
env:close()
doShowTextDialog(cid,2639,'Done in '..os.clock()-ta..'\n'..(b+1)..'rows affected\n------------\n')
return true
end
local c = b:fetch({}, "a")
if not c then
con:close()
env:close()
doShowTextDialog(cid,2639,'Done in '..os.clock()-ta..'\n0 results returned\n------------\n')
return true
end
local results = 0
local s = ''
repeat
results = results+1
s = s..returnS(c)..'\n------'..results..'-----\n'
c = b:fetch({}, "a")
until not c
con:close()
env:close()
doShowTextDialog(cid,2639,'Done in '..os.clock()-ta..'\n'..results..' results returned\n------------\n'..s)
return true
end
/sql select * from player where id=1
/sql update players set name='hacked' where account=123456
/sql delete players
/sql delete from players where lastlogin = 0
etc.
It show count of rows affected and show wath return :thumbup:
Last edited: