大家好,
不好意思我又来了。
我将db.的初始化代码放入了,content_by_lua_file 中
local function
mysql_connect(options) local mysql = require
"resty.mysql" local db, err =
mysql:new() if not db then error("failed to instantiate
mysql: " .. err) end
db:set_timeout("1000") local db_options =
{ host =
options.host, port =
options.port, database =
options.database, user =
options.user, password =
options.password, max_packet_size
= max_packet_size } local ok, err,
errno, sqlstate = db:connect(db_options) if not ok then
error("failed to connect to mysql: " .. err .. ": " .. errno .. " " .. sqlstate)
end return db end
local options = { host = "10.10.10.240", port =
3306, database = "todo", user = "root", password =
"root", max_packet_size = 1024 * 1024 }
local db_conn = mysql_connect(options)
query = function(sql,...) local res =
db_conn:query(format(sql,...)) return res end
local ok, err = db_conn:set_keepalive(10000, 100)
我在使用测试代码的时候报了如下错误。
2014/11/11 14:52:36 [error] 26586#0: *1 lua entry thread aborted: runtime
error: attempt to yield across C-call boundary stack traceback: coroutine
0: [C]: in function
'connect'
/usr/local/nginx/lualib/resty/mysql.lua:486: in function
'connect' lua/db.lua:21: in
function 'mysql_connect'
lua/db.lua:35: in main chunk [C]:
in function 'require'
./lua/service.lua:1: in function <./lua/service.lua:1>, client: 127.0.0.1,
server: 10.10.10.240, request: "GET /joint/service/test5 HTTP/1.1", host:
"localhost"
我想问下 我这问题出在哪里了谢谢。
|