How to connect & query MySQL from within Lua?

前端 未结 3 1945
南笙
南笙 2021-02-07 18:48

How can I connect to a MySQL database from using Lua programming language?

If a good/popular library exists, what is it?

3条回答
  •  深忆病人
    2021-02-07 19:23

    From LuaSQL -- Database connectivity for the Lua programming language:

    require "luasql.mysql"
    env = assert (luasql.mysql())
    con = assert (env:connect"my_db")
    for id, name, address in rows (con, "select * from contacts") do
      print (string.format ("%s: %s", name, address))
    end
    

提交回复
热议问题