local mysql = require ("resty.mysql")
local cjson = require ("cjson")
local pool = {}
local config = {
host = "10.10.12.51",
port = 3306,
database= "xcwork",
user = "root",
password = "xuzhi",
max_package_size = 1024*1024
}
function pool:getConnect()
if ngx.ctx[pool] then
ngx.say("直接从连接池中取Connection.")
return true, ngx.ctx[pool]
end
local dataBase, errmsg = mysql:new()
if not dataBase then
ngx.say("initail mysql connection : ")
ngx.say(errmsg)
return nil
end
-- 10秒
dataBase:set_timeout(10000)
local result, errmsg, errno, sqlstate = dataBase:connect(config)
if not result then
ngx.say("host mysql conne