localsql_normal=[[select id, name from user where name=']] ..ngx.var.arg_name..[[' and password=']] ..ngx.var.arg_password..[[' limit 1;]]localres=ngx.location.capture('/postgres', { args= {sql=sql } })localbody=json.decode(res.body)if (table.getn(res) >0) {returnres[1];}returnnil;
假设我们在用户登录使用上述 SQL 语句查询账号和密码是否正确,用户可以通过 GET 方式请求并发送登录信息比如:
local name = ngx.quote_sql_str(ngx.var.arg_name)
local password = ngx.quote_sql_str(ngx.var.arg_password)
local sql_normal = [[select id, name from user where name=]] ..
name .. [[ and password=]] ..
password .. [[ limit 1;]]
local res = ngx.location.capture(
'/postgres',
{ args = {sql = sql } }
)
local body = json.decode(res.body)
if (table.getn(res) > 0) {
return res[1];
}
return nil;