1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| ngx.say("--查询user--","<br/>")
local select_sql = "select id, ch from user" res,err,errno,sqlstate=db:query(select_sql) if not res then ngx.say("select error:",err,"errno:",errno,",sqlstate:",sqlstate) return close_db(db) end
for i, row in ipairs(res) do for name,value in pairs(row) do ngx.say("select row",i,":",name,"=",value,"<br/>") end end
ngx.say("--查询user-根据ch参数--","<br/>") local ch_param = ngx.req.get_uri_args()["ch"] or '' local query_sql = "select id,ch from user where ch = " .. ngx.quote_sql_str(ch_param) res,err,errno,sqlstate = db:query (query_sql) if not res then ngx.say("select error:",err,",errno:",errno,"salstate:",sqlstate) return close_db (db) end
for i, row in ipairs (res) do for name,value in pairs (row) do ngx.say ("select row",i,":",name,"=",value,"<br/>") end end
|