lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:236: attempt to perform arithmetic on field ‘packet_no’ (a nil value)
在使用OpenResty 利用lua查询mysql数据时遇到了查不到数据的情况 折腾了很久看来很多博客还是没有解决 突然想到可以去看看日志于是在/usr/local/openresty/nginx/logs
2022/02/06 21:30:52 [error] 2736#2736: *71 lua tcp socket read timed out, client: 192.168.44.1, server: localhost, request: "GET /update_content?id=100 HTTP/1.1", host: "192.168.44.38"
2022/02/06 21:30:52 [error] 2736#2736: *71 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:236: attempt to perform arithmetic on field 'packet_no' (a nil value)
stack traceback:
coroutine 0:
/usr/local/openresty/lualib/resty/mysql.lua: in function '_send_packet'
/usr/local/openresty/lualib/resty/mysql.lua:781: in function 'close'
/root/lua/update_content.lua:21: in main chunk, client: 192.168.44.1, server: localhost, request: "GET /update_content?id=100 HTTP/1.1", host: "192.168.44.38"
提示引入的库在使用函数时报错然后在自己写的 /root/lua/update_content.lua:21 行报错
ngx.header.content_type="application/json;charset=utf8"
local cjson = require("cjson")
local mysql = require("resty.mysql")
local uri_args = ngx.req.get_uri_args()
local id = uri_args["id"]
local db = mysql:new()
db:set_timeout(10000)
local props = {
host = "192.168.44.38",
port = 3306,
database = "legou",
user = "root",
password = "root"
}
local res = db:connect(props)
local select_sql = "SELECT id_,is_parent_,order_,parent_id_,title_,expand_ FROM category_ WHERE id_= "..id
res = db:query(select_sql)
local redis = require("resty.redis")
local red = redis:new()
red:set_timeout(20000)
local ip ="192.168.44.38"
"update_content.lua" 33L, 772C
|