Prepared statements for Lua with LuaSQL

北城余情 提交于 2019-12-11 10:55:35

问题


There is little documentation on prepared statements in luaSQL. So i tried to put together some code to use prepared statements in LuaSQL. Unfortunately it's not working.
(I'm using a mysql database)

luasql = require "luasql.mysql"
env = assert (luasql.mysql())
con = assert (env:connect("database","user","password","localhost"))
name = "insert_sql_injection_code_here"
query= "INSERT INTO `table`(`text`) VALUES ('"..name.."')"
cur = assert (con:execute(query))
-- As you can see, query is vulnerable to SQLinjection. Fix: use prepared statements:
smtp = assert(con:prepare("insert into settings (text) values(:p_name)"))
con:bind_names({p_name=name})
cur = assert (con:execute())

Gives the output:

lua: test.lua:8: attempt to call method 'prepare' (a nil value)

Has anyone a working example of prepared statements in Lua with LuaSQL?

来源:https://stackoverflow.com/questions/32670262/prepared-statements-for-lua-with-luasql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!