lua-resty-postgres
lua-resty-postgres copied to clipboard
cannot send query in the current context: nil: nil: nil.
luarocks install lua-resty-postgres
....
local db = pgsql:new()
db:set_timeout(3000)
local ok,err = db:connect({database= config.pgsql.database ,
host = config.pgsql.host,
port = config.pgsql.port,
user = config.pgsql.user,
password = config.pgsql.password,compact = false
})
if not ok then
ngx.say(err)
end
-- db:set_timeout(conf.timeout) -- 1 sec
-- local ok, err, errno, sqlstate = db:connect(conf.pgsql)
-- local ok, err, errno, sqlstate = db:connect()
-- if not ok then
-- ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
-- return
-- end
-- ngx.log(ngx.ERR, "connected to pgsql, reused_times:", db:get_reused_times(), " sql:", sql)
-- db:query("SET NAMES utf8")
ngx.log(ngx.ERR,"sql is ----- ",sql)
local res, err, errno, sqlstate = db:query(sql)
db:set_keepalive(0,100)
if not res then
ngx.log(ngx.ERR, "bad result: ", err, ": ", errno, ": ", sqlstate, ".")
end
-- local ok, err = db:set_keepalive(conf.pool_config.max_idle_timeout, conf.pool_config.pool_size)
-- if not ok then
-- ngx.say("failed to set keepalive: ", err)
-- end
return res, err, errno, sqlstate
db.lua:77: query(): bad result: failed to send query: cannot send query in the current context: nil: nil: nil.,