Hello!
2013/12/10 bm bm:
> nginx配置--nginx.conf:
> location /register {
> access_log logs/host.access.log main;
> content_by_lua_file "conf/mysql.lua";
> }
> ----------------------------------------------------
> lua脚本--mysql.lua:
> 数据库连接部分就不贴出来了,都是按https://github.com/agentzh/lua-resty-mysql#read_result文档做的;
>
> res, err, errno, sqlstate = db:query("update rad set op='yes' where
> rek="..'yesno')
> if not res then
> ngx.say("red bad: ", err, ": ", errno, ": ", sqlstate, ".")
> return
> end
> --------------------------------------------------
> 在IE浏览器中返回:
> red bad: Unknown column 'yesno' in 'where clause': 1054: 42S22.
> -------------------------------------
> 数据库中的表red是有rek字段,值也是为yesno
> ----------------------------------------
>
你这里犯低级错误了。你混淆了 Lua 字符串常量和 SQL 字符串常量。你上面的 Lua 代码发送的 SQL 查询串其实是
update rad set op='yes' where rek=yesno
而你这里需要的显然是
update rad set op='yes' where rek='yesno'
由于你没有使用单引号把 yesno 这个值给引起来,所以 MySQL 服务器将之识别为数据库列名,于是返回了“Unknown column
'yesno'”这个错误消息。
正确的 Lua 代码应当是
local res, err, errno, sqlstate =
db:query("update rad set op='yes' where rek='yesno'")
或者
local res, err, errno, sqlstate =
db:query("update rad set op='yes' where rek="
.. ngx.quote_sql_str("yesno"))
一个建议是调试时总是在 Lua 里面打印出执行的 SQL 查询,以避免这一类和 SQL 拼串相关的低级错误。
> 请问lua-resty-mysql是不是不支持update命令
>
当然支持。
同时抄送给 openresty 中文邮件列表:https://groups.google.com/group/openresty
建议你也加入此列表并在那里讨论这样的问题。谢谢合作!
Regards,
-agentzh